Question 1 :
public class MaheshLoopingExample1 {
public static void main(String[] args) {
int i = 4;
while (i > 0) {
System.out.print(i + ", ");
i--;
}
}
}
Option 1:
A. 4, 3, 2, 1,
B. infinite loop
C. 4, 3, 2
D. Compile Time error
Question 2: // duplicate question
public class MaheshLoopingExample2 {
public static void main(String[] args) {
int i = 4;
while (i > 0) {
System.out.print(i + ", ");
i--;
}
}
}
Options 2:
A. Compile Time error
B. Infinite loop
C. 4, 3, 2
D. 4, 3, 2, 1,
Question 3:
public class MaheshLoopingExample3 {
public static void main(String[] args) {
int i;
for (i = 0, System.out.println("intializer"); i < 1; i++,
System.out.println("increment")) {
System.out.println("body");
}
}
}
Option 3:
A. Compile time error
B. initializer
body
increment
C. initializer
increment
body
D. initializer
body
increment
initializer
Question 4:
public class MaheshLoopingExample4 {
public static void main(String[] args) {
int k;
for (int i = 0; i < k; i++)
System.out.println("loop" + i);
System.out.println("main end");
}
}
Option 4:
A. infinite loop
B. compile time error
C. loop 0
main end
D. main end
Question 5:
public class MaheshLoopingExample1 {
public static void main(String[] args) {
loop1: for (int i = 0; i < 3; i++) {
System.out.print(" loop begin");
if (i > 1) {
break;
System.out.print(" ,from if");
}
System.out.print(" ,loop end");
}
System.out.print(", from main");
}
}
Option 5:
A. compile time error
B. loop begin ,from if, loop end loop begin , from if, loop end loop begin,
from main
C. loop begin ,loop end loop begin ,loop end loop begin, from main
D. loop begin, from main
Question 6:
public class MaheshLoopingExample6 {
public static void main(String[] args) {
int i = 0;
System.out.println("hello to all");
while (i < 4)
;
{
i++;
}
System.out.println(i);
}
}
Option 6:
A. hello to all
4
B. compile time error
C. hello to all
infinite loop
D. hello to all
Question 7:
public class MaheshLoopingExample7 {
public static void main(String[] args) {
int[] a = { 10, 20, 30, 40, 55 };
for (int i : a) {
System.out.print(i + ",");
}
}
}
Option 7:
A. 10,20,30,40,55,
B. infinite loop
C. compile time error
D. 10,20,30,40,55
Question 8:
public class MaheshLoopingExample8 {
public static void main(String[] args) {
int i;
for (i = 0; i < 1; i++)
;
System.out.println(i);
System.out.println(i);
}
}
Option 8:
A. 1
1
B. 0
1
C. 0
0
D. Compile time error
Question 9:
public class MaheshLoopingExample9 {
public static void main(String[] args) {
int i = 0;
do {
System.out.println("body:" + i);
i++;
} while (i > 10);
}
}
Option 9:
A. body: 0
infinite loop
B. body: 10
C. body: 0
D. compile time error
Question 10:
public class MaheshLoopingExample10 {
public static void main(String[] args) {
for (int i = 0; i < 1; i++)
;
System.out.println(i);
}
}
Option 10:
A. 0
B. 1
C. No output to display
D. Compile time error
Question 11:
public class MaheshLoopingExample11 {
public static void main(String[] args) {
for (int i = 0, j = 4; i < 2; i++, j--)
System.out.println(i + " " + j);
}
}
Option 11:
A. 0 4
1 3
B. 0 4
1 3
2 2
C. Compile time error
D. 0 4
Question 12:
public class MaheshLoopingExample13 {
public static void main(String[] args) {
int i;
for (i = 0; i < 1; i++) {
System.out.println("loop:" + i);
}
System.out.println("main:" + i);
}
}
Option 12:
A. loop:1
main:1
B. loop:0
main:0
C. loop:0
main:1
D. Compile time error
Question 13:
public class MaheshLoopingExample13 {
public static void main(String[] args) {
int i;
for (int i = 2; i < 2; i++) {
System.out.println("from loop");
}
}
}
Option 13:
A. from loop
from loop
B. compile time error
C. from loop
D. no output to display
Question 14:
public class MaheshLoopingExample14 {
public static void main(String[] args) {
for (int i = 0; i < 1; i++) {
System.out.println("loop:" + i);
}
System.out.println("main:" + i);
}
}
Option 14:
A. loop:1
main:1
B. loop:0
main:0
C. loop:0
main:1
D. Compile time error
Question 15:
public class MaheshLoopingExample15 {
public static void main(String[] args) {
int i;
for (i = 0; i < 2; i++) {
for (int i = 0; i < 1; i++)
System.out.println("from loop");
}
}
}
Options 15 :
A. from loop
from loop
from loop
B. compile time error
C. from loop
D. no output to display
Question 16:
public class MaheshLoopingExample16 {
public static void main(String[] args) {
int i = 4;
while (i > 0) {
i--;
}
System.out.print(i);
}
}
Options 16:
A. 0
B. 1
C. Compile time error
D. 1, 2, 3, 4
Question 17:
public class MaheshLoopingExample17 {
public static void main(String[] args) {
for (int i = 0; i > 0; i++) {
System.out.println("loop:" + i);
}
System.out.println("main end");
}
}
Option 18:
A. main end
B. compile time error
C. loop: 0
main end
D. no output to display
Question 19:
public class MaheshLoopingExample19 {
public static void main(String[] args) {
for (int i = 0, j = 8; (i < 4 && j > 4); i++, j--)
System.out.println(i + " " + j);
}
}
Options 19:
A.
0 8
1 7
2 6
B. compile time error
C.
0 8
1 7
2 6
3 5
D. 0 8
Question 20:
public class MaheshLoopingExample20 {
public static void main(String[] args) {
loop1: for (int i = 0; i < 3; i++) {
System.out.print(" loop begin");
if (i > 1) {
break;
}
System.out.print(" ,loop end");
}
System.out.print(", from main");
}
}
Options 20:
A. loop begin ,loop end loop begin ,loop end loop begin, from main
B. loop begin ,loop end loop begin ,loop end loop begin
C. compile time error
D. loop begin ,loop end loop begin ,loop end loop begin, loop end from main
Question 21:
public class MaheshLoopingExample21 {
public static void main(String[] args)
{
int[] x={10,20,30};
int i;
for(i : x)
{
System.out.print(i);
}
}
}
Options 21:
A. 10, 20, 30
B. compile time error
C. infinite loop
D. 10