What is the output of the following code? (5 pnts) public class Loopy { public static void main(String[] args) { int x = 1; System.out.println("Before the loop"); while (x < 4) { System.out.println("In the loop"); System.out.println("Value of x is " + x); x = x + 1; } System.out.println("This is after the loop"); }
1. What is the output of the following code? (5 pnts)
public class Loopy {
public static void main(String[] args) {
int x = 1;
System.out.println("Before the loop");
while (x < 4) {
System.out.println("In the loop");
System.out.println("Value of x is " + x);
x = x + 1;
}
System.out.println("This is after the loop");
}
}
Try first by eye, then verify your results via eclipse.
Submission
• Submit only the answers.
2. Write a program called KiloToPoundTable that prints the below table. Use
printf()and while statement. No credit if while statement is not used. (10 pnts)
Kilograms Pounds
1 2.2
3 6.6
5 11.0
7 15.4
9 19.8
11 24.3
13 28.7
15 33.1
1) 1 kilogram is 2.20462 pounds (so, 2nd row will be 3 * 2.20462)
2) Use while statement to iterate
3) Set width to 12 for each column
4) Use printf() for precision up to tenths place
Step by step
Solved in 2 steps