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
What includes two or more private, public, or community clouds, but each cloud remains separate and is only linked by technology
Ilya [14]

Answer:

hybrid cloud

Explanation:

hybrid cloud is a cloud environment that employs both public and private cloud services.

Hybrid cloud gives businesses more flexibility and greater efficiency in coverage due to its ability to move files between public and private cloud.

7 0
3 years ago
Sypherpk is good go sub 2 him
attashe74 [19]

Answer:

Ok

Explanation:

I will check him out, do you need anything else though?

4 0
3 years ago
Read 2 more answers
HURRY
Irina-Kira [14]

<em>Your answer is B: cooperative player-to-player interaction</em>

<em></em>

<em></em>

<em />

6 0
3 years ago
How is communication within healthcare different than communication within other industries ?
vfiekz [6]

Answer:

It has to be more specific and easier to understand because of its importance.

Explanation:

7 0
3 years ago
1) ( IBADE - 2020)A legislação que regula o uso da Internet no Brasil por meio da previsão de princípios, garantias, direitos e
VARVARA [1.3K]
C) Lei da Regulação Digital :)
6 0
3 years ago
Other questions:
  • How do u change the level of education on Brainly. cuz i just finished elementry
    9·2 answers
  • To expand a window to the full size of the screen.​
    6·2 answers
  • One form of e-mail attack that is also a DoS attack is called a mail spoof, in which an attacker overwhelms the receiver with ex
    14·1 answer
  • As defined by the National Institute of Standards and Technology​ (NIST), "________ is a model for enabling​ ubiquitous, conveni
    11·1 answer
  • Complete the sentence.<br> A ___ number is composed of only zeros and ones.
    8·1 answer
  • Why bootable installer preparation is important? explain
    9·1 answer
  • Describe the job of an Architect.
    5·2 answers
  • Add Try/Catch error checking To make sure that the user enters valid values in your program. To catch negative values passed to
    9·1 answer
  • What is the second step when designing an algorithm?
    12·2 answers
  • How is the architecture converted into software code? Elaborate the steps its passes through with help of examples / Diagram.
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!