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
PLEASE HELPPPPP ASAP, 50 POINT'S + BRAINLIEST
vagabundo [1.1K]

Answer:

1. Cybercrimes are online crimes that cause loss of money some examples are: Identity fraud, Cyber bribery, Debit/credit card fr/ud, and Email fr/ud.  

2. In medical offices devices linked to CT scans are able to be h/cked, there is r/nsomw/re that uses their devices. Since medic/l computers are always linked to the internet. it makes it easier for them to be h/cked. They make an employee click on an e-mail carrying m/lw/re, then the cybercrimin/ls encrypt p/tient data then dem/nd p/yment for its decryption.

3. This is a personal question but if you have ever been sc/mmed or witnessed someone being sc/mmed or almost got  sc/mmed it might apply to this question

6 0
2 years ago
. Hackers generally disguise their IP address. True False
maw [93]
I think that's true.
If they didn't they could be easily tracked by the police.
4 0
3 years ago
To display “ hello ” message on the screen
Alex787 [66]

Answer:

hello like that

it's in order

4 0
3 years ago
A buffer storage that improve computer performance by reducing access time is​
kvasek [131]
Cache memory

Hope it helps
4 0
3 years ago
Which certification can help enhance your job prospects in the role of a computer programmer?
Paraphin [41]
Computer science certification, Linux professionalism, Java certification, Python certification
6 0
2 years ago
Read 2 more answers
Other questions:
  • Wordwrap forces you to stop typing words and press the enter key at the end of each line.
    12·1 answer
  • rob just got a new idea for the movie he's making, and he wants to put in late hours to get it done. Which of the following stat
    10·1 answer
  • A book of the Law was found in the Temple, which was being repaired, during what year of Josiah's reign.
    15·2 answers
  • Define a function CoordTransform() that transforms the function's first two input parameters xVal and yVal into two output param
    12·1 answer
  • What is this line of code doing? scanf("%f", &height);
    6·1 answer
  • Is badlion safe and how ?
    14·1 answer
  • When you use information hiding by selecting which properties and methods of a class to make public, you are assured that your d
    14·1 answer
  • Which media example would be best for mayas presentation
    7·1 answer
  • How do I make someone "Brainiest". <br> First person to reply will get "Brainiest"
    8·2 answers
  • A form of segmentation that is based on user usage rate, user status, purchase occasion, and benefits sought is _________.
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!