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
When you call a ____________ method, it executes statements it contains and then returns a value back to the program statement t
Maksim231197 [3]

Answer:

The answer is a VOID method.

Explanation:

A void method is one that simply performs a task and then terminates.

4 0
4 years ago
Read 2 more answers
# q7 - create function readFileFirstLast() to meet the conditions below
MAVERICK [17]

Answer:

See explaination

Explanation:

def readFileFirstLast(filename):

# doc string

''' Function accept the filename and opens the fle

and reads all lines and strips new line character and

stores first and last in a string and return that string'''

#eception handle if file not found

try:

#opening the file

f = open(filename)

#reading the first line and striping the ne line

string = f.readline().strip()

#iterating until last line

for line in f:

pass

#concate the last line after strip the new line character to the string

string = string + " " + line.strip()

#return the string

return string

except:

#if file not found

return "File not found"

#taking the file name from user

filename = input("Enter a file name: ")

#printing the doc string in function

print("\ndoc_sting: \n"+ readFileFirstLast.__doc__+"\n")

#printing the returned string by calling the readFileFirstLast()

print("output string :")

print(readFileFirstLast(filename))

3 0
3 years ago
Write an if/else statement that compares the value of the variables soldYesterday and soldToday, and based upon that comparison
jenyasd209 [6]

Answer:

if(soldYesterday > soldToday){

salesTrend = -1;

} else if(soldToday > soldYesterday){

salesTrend = 1;

}

Explanation:

The if/else statement is more explicit. The first if condition check if soldYesterday is greater than soldToday, if true, then -1 is assigned to salesTrend.

Else if soldToday is greater than soldYesterday, if true, then 1 is assigned to salesTrend.

7 0
3 years ago
Which one you choosing? PS5 OR THE XBOX SERIES X???
love history [14]

Answer:

PS5

Explanation:

It gooder

3 0
3 years ago
Read 2 more answers
How can I call moderator in braily app ???
SVETLANKA909090 [29]

Hi

You can directly message them.

And just in case you don't know how to message in brainly, then:

If you are using app, then

• Go to your profile and go in the option followers/following.

• There you'll see an option to search, slick that and search the name of moderators.

• Do to there profile and you'll see 2 options ( given in image attached) 1, to follow and 2nd to message.

click \: the \: 2nd \: optionclickthe2ndoption

And just in case, you are using website, then:

• Go to their profile and you'll see an option saying " write a message", click that and you'll able to message them.

Just in case you don't know the names of moderators of Brainly ( you are new here)

So here are some of them:

• Siddhartharao77

• Nikki57

• Praneethworldtopper

• Anvigottlieb

• RehanAhmadXLX

• Abhi178

• Sugarplumprincess

Hope this helps!!!

Thanks...

☺☺

5 0
3 years ago
Other questions:
  • What makes sqlite an appropriate choice for an android application, compared to other relational database management systems, su
    15·1 answer
  • Jessica is working on a report for her art history class. She is using Microsoft Word for her report so that she can incorporate
    6·2 answers
  • In general, WAN-specific standards identify specific security requirements for WAN devices. For example, the ___________________
    10·1 answer
  • The programmer must initialize variables when they are declared
    12·1 answer
  • Choose the best answer to complete the sentence.
    14·1 answer
  • Where are options to add a border around the outside of a chart found?
    9·2 answers
  • During the system investigation stage, __________ studies are done to determine if the hardware, software, and communications co
    9·1 answer
  • What is done to conserve energy while electricity is being transported?
    9·1 answer
  • In the U.S. fuel efficiency of cars is specified in miles per gallon (mpg). In Europe it is often expressed in liters per 100 km
    12·1 answer
  • What’s GIGO<br> Please write it in full form
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!