Java - MCQ

Multiple Choice Questions


Share with a Friend

 

Java MCQ - Loops, Decisions and Mathematical functions - Set 22

11. In java, ............ can only test for equality, where as .......... can evaluate any type of the Boolean expression.
A). switch, if
B). if, switch
C). if, break
D). continue, if
View Answer
Correct: A



12. Which of the following for loops will be an infinite loop?
A). for (;;)
B). for (i=0;i<1;i--)
C). for(i=0;;i++)
D). All of the above
View Answer
Correct: D



13. Determine output:

public class Test{
        public static void main(String args[]){
                int i; 
                for(i = 1; i < 6; i++){ 
                        if(i > 3) continue ; 
                }
                System.out.println(i); 
        }
}

A). 2
B). 3
C). 4
D). 6
View Answer
Correct: D



14. Consider the following program written in Java.

class Test{
        public static void main(String args[]){
                int x=7; 
                if(x==2); 
                System.out.println("NumberSeven");
                System.out.println("NotSeven");
        }
}
What would the output of the program be?
A). NumberSeven NotSeven
B). NumberSeven
C). NotSeven
D). Error
View Answer
Correct: A



15. Determine output:

public class Test{
        public static void main(String args[]){
                int i, j;
                for(i=1, j=0;i<10;i++) j += i;
                System.out.println(i);
        }
}
A). 10
B). 11
C). 9
D). 20
View Answer
Correct: A



 
 
 
   
   
   
UltraInfo Technologies
ITDeveloper