Computer Applications
Rewrite the following do while program segment using for:
x = 10; y = 20;
do
{
x++;
y++;
} while (x<=20);
System.out.println(x * y );
Java Iterative Stmts
ICSE 2024
4 Likes
Answer
Below is the for
loop version of the provided do-while
segment:
public class Main {
public static void main(String[] args) {
int x = 10, y = 20;
for (; x <= 20; x++, y++) {
// Body is empty because the increments are in the for loop header
}
System.out.println(x * y);
}
}
Answered By
3 Likes
Related Questions
Write Java expression for:
Evaluate the expression when x is 4:
x += x++ * ++x % 2;
Give the output of the following program segment. How many times is the loop executed?
for(x=10; x>20;x++) System.out.println(x); System.out.println(x*2);
String s1 = "45.50"; String s2 = "54.50"; double d1=Double.parseDouble(s1); double d2=Double.parseDouble(s2); int x= (int)(d1+d2);
What is value of x?