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
padilas [110]
3 years ago
11

The Double.parseDouble() method requires a String argument, but it fails if the String cannot be converted to a floating-point n

umber. Write an application in which you try accepting a double input from a user and catch a NumberFormatException if one is thrown. The catch block forces the number to 0 and displays Value entered cannot be converted to a floating-point number. Following the catch block, display the number.
Computers and Technology
1 answer:
Andrei [34K]3 years ago
3 0

Answer:

  1. import java.util.Scanner;
  2. public class Main {
  3.    public static void main(String[] args) {
  4.        Scanner input = new Scanner(System.in);
  5.        String numStr = input.nextLine();
  6.        double num;
  7.        try{
  8.            num = Double.parseDouble(numStr);
  9.        }
  10.        catch(NumberFormatException e){
  11.            num = 0;
  12.            System.out.println("Value entered cannot be converted to a floating point number.");
  13.        }
  14.    }
  15. }

Explanation:

The solution code is written in Java.

Firstly, we create a Scanner object and prompt user to input a number (Line 5-6). Next, we create a try -catch block and place the parseDouble inside the try block. If the input is invalid (e.g. "abc"), a NumberFormatException error will be thrown and captured and set the num to 0 and display the error message (Line 11 - 13).  

You might be interested in
Which of the following is a file on the host computer used for temporary memory storage when a sudden surge in memory requiremen
o-na [289]

Answer:

The answer is memory buffer.

Explanation:

Which of the following is a file on the host computer used for temporary memory storage when a sudden surge in memory requirements exceeds the physical amount of memory available?

The answer is memory buffer.

A buffer, also called buffer memory, is a portion of a computer's memory that is set aside as a temporary holding place for data that is being sent to or received from an external device, such as a hard disk drive (HDD), keyboard or printer.

4 0
3 years ago
Provide the subnet, broadcast address and the valid host ranges for each of the
avanturin [10]

Answer:

You should now be able to give IP addresses to 254 hosts. This works fine if all 150 computers are on a single network. However, your 150 computers are on three separate physical networks. Instead of requesting more address blocks for each network, you divide your network into subnets that enable you to use one block of addresses on multiple physical networks

Explanation:

3 0
3 years ago
What is (12.2a + 9.7b) – (18.1b – 0.2a) – (6.7a + 6.8b), simplified?
Inga [223]
The answer should be 5.7a - 15.2b
8 0
3 years ago
Which range function creates the following list of numbers?<br> 76 74 72 70 68 66 64 62
baherus [9]

Answer:

they look like even number

Explanation:

2 4 6 8 10 12 -------seeeeee but not hundred percent sure but plz put me in brainlist

4 0
3 years ago
Where do you place the logical test argument in an IF function formula?
Inessa [10]

Answer:

The first argument listed after IF

Explanation:

When the two variables are listed next to each other, Excel will find and calculate the correlation between them.

8 0
3 years ago
Read 2 more answers
Other questions:
  • When using a graphics editing program, which option allows you to adjust the space around an image?
    15·1 answer
  • All of the following are typical characteristics of internet predators, except white. male. between the ages of 18 and 35. high
    7·1 answer
  • "In about 100 words, describe the idea behind software as a service (SaaS). In your answer, include at least three examples of e
    10·1 answer
  • Write a complete program whose class name is hello and that displays hello, world on the screen.
    13·2 answers
  • Application servers are usually grouped into two types: page-based and _____ systems.
    6·1 answer
  • Bitmap images are ________ into different software applications.
    9·1 answer
  • Referat noaptea la școala cu sfârșit de groază​
    10·1 answer
  • Describe the forward button​
    7·1 answer
  • In order to restrict editing to a document, a user will go to Review, , Restrict Editing, and will then select what kinds of edi
    12·1 answer
  • How do you enter the decimal 73 into the computer?
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!