Java - MCQ

Multiple Choice Questions


Share with a Friend

 

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

21. What will be the output?

public class Test{
      public static void main(String args[]){ 
            int i = 1;
            do{
                  i--;
            }while(i > 2);
            System.out.println(i);
      }
}
A). 1
B). 2
C). -1
D). 0
View Answer
Correct: D



22. What will be the result?

  int i = 10;
  while(i++ <= 10){
        i++;
  }
  System.out.print(i);
A). 10
B). 11
C). 12
D). 13
View Answer
Correct: D



23. What will be the result of compiling and runnig the following code:

public class Test{
      public static void main(String... args) throws Exception{
            Integer i = 34;
            int l = 34;
            if(i.equals(l)){
                  System.out.println("true");
            }else{
                  System.out.println("false");
            }
      }
}
A). true
B). false
C). Compiler error
D). None of these
View Answer
Correct: A



24

1. public class Test{
2.       public static void main(String [] args){
3.             int x = 0;
4.             // insert code here
5.             do{ } while(x++ < y);
6.             System.out.println(x);
7.       }
8. }
24. Which option, inserted at line 4, produces the output 12?
A). int y = x;
B). int y = 10;
C). int y = 11;
D). int y = 12;
View Answer
Correct: C



25. What will be the result?

1.  int i = 10;
2.  while(i++ <= 10){
3.        i++;
4.  }
5.  System.out.print(i);
A). Line 5 will be never reached.
B). 11
C). 12
D). 13
View Answer
Correct: D



 
 
 
   
   
   
UltraInfo Technologies
ITDeveloper