Test Series - java

Test Number 38/64

Q: What is the output of the below Java program?
int time=50;
do
{
System.out.print(time + ",");
time++;
}while(time < 53)
A. 50,50,50,
B. 50,51,52,
C. 51,52,53,
D. Compiler error
Solution: The semicolon after the WHILE (Condition) is missing.
Q: What is the output of the below Java program?
String str[] = {"A","B","C"};
int i=0;
do
{
  if(i>= str.length)
    break;
  System.out.print(str[i] + ",");
  i++;
}while(true);
A. A,B,C,
B. A,B,C
C. Runtime Exception with Index Of Bounds Exception
D. Compiler error
Solution: no solution
Q: What is the output of the below Java code with a FOR loop?
for(int i=1; i<5; i++)
{
  System.out.print(i +",");
}
A. 1,2,3,4
B. 1,2,3,4,
C. 1,2,3,4,5,
D. 1,2,3,4,5
Solution: no solution
Q: What is the output of the below Java code?
boolean[] ary = {true, false, true, true};
for(int i=0; i
A. true,true,true,true,
B. true,false,false,true
C. true,false,true,true
D. Compiler error
Solution: no solution
Q: What is the output of the below Java code?
int score=1;
for(; true; score++)
{
  System.out.print(score +",");
  if(score > 3)
    break;
}
A.  1,2,3,
B. 1,2,3
C. 1,2,3,4,
D. 1,2,3,4
Solution: BREAK condition is checked after printing the variable "score". So, it prints 4 also.
Q: What is the output of the below Java program with FOR loop?
for(int j=0; j<5;j++;)
  System.out.print(j + ",");
A. 1,2,3,4,
B. 0,1,2,3,4
C. Compiler error
D. None
Solution: The semicolon after the INCREMENT/DECREMENT part is not allowed.
Q: State TRUE or FALSE. In a FOR loop, the Initialization-part, Condition-part and Increment/Decrement part can be empty.
A.  FALSE
B. TRUE
C. blank
D. None
Solution: for(;;) is valid.
Q: Any loop can be nested inside any loop in Java. (TRUE/FALSE).
A. FALSE
B. TRUE
C. blank
D. None
Solution: no solution
Q: A Loop in Java language may contain ___.
A. Any loop
B. IF-ELSE statements
C. SWITCH statements
D. All
Solution: no solution

You Have Score    /9