Which loop structure in Java allows the code block to be executed at least once, even if the condition is false initially?
1 Crore+ students have signed up on EduRev. Have you? Download the App |
Which loop structure is best suited for iterating over an array or a collection?
What is the output of the following code snippet?
int i = 0;
while (i < 5) {
System.out.print(i + " ");
i++;
}
What is the output of the following code snippet?
for (int i = 10; i > 0; i -= 2) {
System.out.print(i + " ");
}
What is the output of the following code snippet?
int i = 0;
do {
System.out.print(i + " ");
i++;
} while (i < 5);
Which loop structure is best suited when the number of iterations is known in advance?
What is the output of the following code snippet?
int i = 5;
while (i > 0) {
System.out.print(i + " ");
i--;
}
What is the output of the following code snippet?
int sum = 0;
for (int i = 1; i <= 5; i++) {
sum += i;
}
System.out.println(sum);
What is the output of the following code snippet?
int x = 3;
while (x > 0) {
System.out.print(x + " ");
x--;
}
What is the output of the following code snippet?
int i = 0;
do {
System.out.print(i + " ");
i += 2;
} while (i < 5);
What is the output of the following code snippet?
int i = 10;
do {
System.out.print(i + " ");
i -= 3;
} while (i > 0);
What is the output of the following code snippet?
int i = 0;
while (i < 5) {
System.out.print(i + " ");
i++;
if (i == 3) {
break;
}
}
What is the output of the following code snippet?
int i = 0;
while (i < 5) {
if (i % 2 == 0) {
i++;
continue;
}
System.out.print(i + " ");
i++;
}
What is the output of the following code snippet?
int i = 0;
while (i < 3) {
int j = 0;
while (j < 2) {
System.out.print(i + "" + j + " ");
j++;
}
i++;
}
What is the output of the following code snippet?
int i = 1;
while (i <= 3) {
for (int j = 0; j < i; j++) {
System.out.print("*");
}
System.out.println();
i++;
}
What is the output of the following code snippet?
int i = 2;
while (i <= 6) {
System.out.print(i + " ");
i += 2;
}
What is the output of the following code snippet?
int i = 1;
while (i < 5) {
if (i == 3) {
i++;
continue;
}
System.out.print(i + " ");
i++;
}
60 videos|37 docs|12 tests
|
60 videos|37 docs|12 tests
|