Java Reference
In-Depth Information
{
num = console.nextInt();
sum = sum + num;
}
System.out.println("Sum = " + sum);
29. Which of the following apply to the while loop only? To the do ... while
loop only? To both?
a. It is considered a conditional loop.
b. The body of the loop executes at least once.
c. The logical expression controlling the loop is evaluated before the loop
is entered.
d. The body of the loop might not execute at all.
30. The following program has more than five mistakes that prevent it from
compiling and/or running. Correct all such mistakes.
public class Exercise30
{
final int N = 2,137;
public static main(String[] args)
{
int a, b, c, d:
a := 3;
b = 5;
c = c + d;
N = a + n;
for (i = 3; i <= N; i++)
{
System.out.print(" " + i);
i = i + 1;
}
System.out.println();
}
}
31. What is the difference between a pretest loop and a posttest loop?
32. How many times will each of the following loops execute? What is the
output in each case?
x = 5;
y = 50;
a.
do
x = x + 10;
while (x < y);
System.out.println(x + " " + y);
Search WWH ::




Custom Search