Question
Asked Mar 26, 2019
1 views

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
help_outline

Image Transcriptionclose

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

fullscreen
check_circle

Expert Answer

Step 1

1. Algorithm for the given code is as follows:

The variable ""x is initialized as "1" within the "main()" function.

If the variable "x" is equal to "1" then it print "Before the loop".

If the variable "x" is less than "4" then it print "In the loop".

If the variable "x" is greater than "4" then it print "This is after the loop".

Step 2

Output of the given program is as follows:

fullscreen
Step 3

2. The program has the following algorithm:

  1. The variables “pound”, and “kilo” is initialized within the “main()” function.
  2. The “while” statemen...

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in

Engineering

Computer Science

Related Computer Science Q&A

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

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...

question_answer

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 ...

question_answer

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...

question_answer

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...

question_answer

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

question_answer

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...

question_answer

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...

question_answer

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...

question_answer

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...