The correct output of the following code is | Scala Question 1

10. The correct output of the following code is,

object MyClass {
    def main(args: Array[String]) {
        var i,j=0
        for(i <- 0 to 3){
            for(j <- 0 until 2){
                if(i + j == 3){
                    print((i*j)+"\t")
                }
            }
        }
    }
}
  1. 3 3
  2. 2 0
  3. 0 2
  4. 1 1

Answer: B) 2 0

Explanation:

In a nested loop, we will print values, The first iteration is 2, 1 and the second is 3, 0.

Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.