Question: Find the error in each of the following code segments, and explain how to correct it: a) i = 1; while (i
Find the error in each of the following code segments, and explain how to correct it:
a)
i = 1;
while (i <= 10);
++i;
}
b)
for (k = 0.1; k != 1.0; k += 0.1) {
System.out.println(k);
}
c)
switch (n) {
case 1:
System.out.println("The number is 1");
case 2:
System.out.println("The number is 2");
break;
default:
System.out.println("The number is not 1 or 2");
break;
}
d) The following code should print the values 1 to 10:
n = 1;
while (n < 10) {
System.out.println(n++);
}
Step by Step Solution
3.40 Rating (159 Votes )
There are 3 Steps involved in it
a Error The semicolon after the while header causes an infinite loop and theres a missi... View full answer
Get step-by-step solutions from verified subject matter experts
