Which of the following statements best describes the need for loops in Java?
Which loop construct in Java is most suitable when the number of iterations is unknown?
1 Crore+ students have signed up on EduRev. Have you? Download the App |
Which loop construct guarantees that the loop body will be executed at least once?
What will be the output of the following code snippet?
int i = 0;
while (i < 5) {
System.out.print(i + " ");
i++;
}
Which of the following loop constructs is used to iterate over an array in Java?
In Java, which loop construct is best suited when the number of iterations is known in advance?
What will be the output of the following code snippet?
int i = 10;
do {
System.out.print(i + " ");
i--;
} while (i > 0);
Which loop construct allows the loop body to be executed at least once?
What will be the output of the following code?
```java
int x = 5;
while (x > 0) {
System.out.print(x + " ");
x -= 2;
}
```
What will be the output of the following code?
```java
int i = 0;
do {
System.out.print(i + " ");
i++;
} while (i < 5);
```
What will be the output of the following code?
```java
int n = 3;
int i = 0;
do {
System.out.print(n + " ");
n--;
i++;
} while (i < n);
```
What will be the output of the following code?
```java
int i = 10;
while (i > 5) {
i--;
}
System.out.print(i);
```
What will be the output of the following code?
```java
int i = 5;
do {
i--;
} while (i > 0);
System.out.print(i);
```
What will be the output of the following code?
```java
int i = 0;
int sum = 0;
while (i < 5) {
sum += i;
i++;
}
System.out.print(sum);
```
What will be the output of the following code?
```java
int i = 5;
while (i > 0) {
System.out.print(i + " ");
i -= 2;
}
```
What will be the output of the following code?
```java
int x = 5;
do {
System.out.print(x + " ");
x++;
} while (x < 10);
```
What will be the output of the following code?
```java
int i = 1;
int sum = 0;
while (i <= 10) {
sum += i;
i++;
}
System.out.print(sum);
```
What will be the output of the following code?
```java
int i = 0;
do {
System.out.print(i + " ");
i += 2;
} while (i <= 5);
```