1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
BaLLatris [955]
3 years ago
13

Code example 5-1 import java.util.Scanner; import java.text.NumberFormat; public class WeightConverter { public static void main

(String[] args) { Scanner sc = new Scanner(System.in); String prompt = "Enter weight in lbs: "; boolean isValid = false; double weightInPounds = 0.0; while (!isValid) { weightInPounds = getDouble(sc, prompt); if (weightInPounds > 0) { isValid = true; } else { System.out.println("Weight must be greater than 0."); } } double weightInKilos = weightInPounds / 2.2; NumberFormat nf = NumberFormat.getNumberInstance(); nf.setMaximumFractionDigits(2); String message = weightInPounds + " lbs\nequals\n" + nf.format(weightInKilos) + " kgs\n"; System.out.print(message); } public static double getDouble(Scanner sc, String prompt) { double d = 0.0; boolean isValid = false; while (!isValid) { System.out.print(prompt); if (sc.hasNextDouble()) { d = sc.nextDouble(); isValid = true; } else { System.out.println ("Error! Invalid decimal value. Try again."); } sc.nextLine(); } return d; } } (Refer to code example 5-1.) If the user enters "two hundred" at the console prompt, what does the code do? a. displays an error message from the main() method b. displays an error message from the getDouble() method c. figures the weight in kilograms d. throws an InputMismatchException
Computers and Technology
1 answer:
Trava [24]3 years ago
4 0

Answer:

It displays an error message from the getDouble() method

Explanation:

The above would be the result because of the following

1. Variable d is declared as a double variable and should be used as such.

2. The getDouble() method is also defined to handle double variables only.

When the program tries to accept at

weightInPounds = getDouble(sc, prompt);

The getDouble method is called immediately and since the value

"two hundred" entered in string, it can't handle this data type and it (the getDouble method) will display an error message

You might be interested in
Convert 30 to hexadecimal ​
Delvig [45]

Answer:

1E

Explanation:

Here is a table to help you. Similar to a multipication table, just follow either the number 3 down to A (aka 10) or 6 x 5 and you will find your answer of

1E = 30

6 0
3 years ago
What is meant by algorithm?​
ExtremeBDS [4]

Answer:

a process or set of rules to be followed in calculations or other problem-solving operations, especially by a computer.

Explanation:

7 0
3 years ago
2. The part of the computer that provides access to the Internet is the A. monitor. B. keyboard. C. system unit. D. modem.
allochka39001 [22]
The modem provides access to the internet.
4 0
3 years ago
Read 2 more answers
How do you install an operating system?<br><br> Answer with full sentences
denis23 [38]

Answer:

On Windows. Insert the installation disk or flash drive. Restart your computer. Wait for the computer's first startup screen to appear. Press and hold Del or F2 to enter the BIOS page. Locate the "Boot Order" section. Select the location from which you want to start your computer.

Explanation:

6 0
3 years ago
Text box linking is for two or more text boxes in a document, when the text overflows from the first box. Which scenario is the
Julli [10]

Answer:

Explanation:

use the next box i think

8 0
3 years ago
Read 2 more answers
Other questions:
  • Which elements in a web page require a visitor’s action?
    15·1 answer
  • Which option organizes tasks based on importance?
    12·1 answer
  • With respect to the general classes of computers, a ________ is the most expensive and most powerful kind of computer, which is
    7·1 answer
  • Which is faster, a hi-speed usb port or a superspeed usb port?
    15·2 answers
  • What is the Matlab command to create a vector of the even whole numbers between 29 and 73?
    11·1 answer
  • 0x400C (in hexadecimal)?
    8·1 answer
  • a) Before writing any code, you should go through a design process. Try to do so carefully – either follow a top-down approach,
    15·1 answer
  • The amount of time taken by each of 10 students in a class to complete an exam is an example of what type of data? a. Cannot be
    15·1 answer
  • Given N lines of input, print the 3rd character from each line as a new line of output. It is guaranteed that each of the n line
    8·1 answer
  • A presentation software that is used to organize and present pertinent information using graphics, word processing, outlining, d
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!