Question

1. What is the output of the following code? 
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");
}
}

2. Write a program called KiloToPoundTable that prints the below table. Use
printf()and while statement. Do not use if while statement. 

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

Kilograms Pounds
2.2
6.6
11.0
15.4
19.8
24.3
28.7
33.1
7
13
15
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 columrn
4) Use printf) for precision up to tenths place

Image Transcription

Kilograms Pounds 2.2 6.6 11.0 15.4 19.8 24.3 28.7 33.1 7 13 15 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 columrn 4) Use printf) for precision up to tenths place

Expert Answer

Want to see the step-by-step answer?

See Answer

Check out a sample Q&A here.

Want to see this answer and more?

Experts are waiting 24/7 to provide step-by-step solutions in as fast as 30 minutes!*

See Answer
*Response times vary by subject and question complexity. Median response time is 34 minutes and may be longer for new subjects.

Related Computer Science Q&A

Find answers to questions asked by student like you
Show more Q&A

Q: Part 1: Stack As mentioned in class, Python 3 provides the LifoQueue class as part of the Queue libr...

A: Import the given class in another file.Create the function postfix() which takes a string as its arg...

Q: Assume the following declarations and initializations (MIN, MAX, num) are made just before each sub-...

A: 1.Program plan:Define the class.Define the “main()” function.Initialize the necessary variables.The ...

Q: Construct the XOR operator using only AND, OR, and NOT gates.

A: XOR gate:An XOR gate is referred to an Exclusive OR gate. The output of an XOR gate is “1” only when...

Q: What are the internal components of a computer that make it function?

A: A computer system consists of multiple hardware devices which, with the help of software, perform co...

Q: What is the output of the following code: public class A{public int methodOfA(int i){i += 10;return ...

A: Given program:File name: A.java

Q: Visual Basic. Given two variables, isEmpty of type boolean, indicating whether a class roster is emp...

A: We have to check two conditions:-1) class roster is not empty 2) The class has more than two credits...

Q: Complete the following programming assignment. Use good programming style and all the concepts previ...

A: Program Instructions:Create four methods named insertionSort(), bubblesort(), mergesort() and quicks...

Q: Find a pda that accepts the language L={anb2n :n≥0}.L={anb2n :n≥0}.

A: Pushdown Automata (PDA):In PDA, we can store one alphabet of language because PDA has only one stack...

Q: The symmetric difference of two sets S1 and S2 is defined as S1 ⊝ S2 = {x : x ∈ S1 or x ∈ S2, but x ...

A: Solution:Given that,The symmetric difference between two sets such as “S1” and “S2” can be expressed...