subject

Write a program that asks the user to input a set of floating-point values. When the user enters a value that is not a number, give the user a second chance to enter the value. After two chances, quit reading input. Add all correctly specified values and print the sum when the user is done entering data. Use exception handling to detect improper inputs. Here is a sample program run:Value: 1Value: 2Value: threeInput error. Try again. Value: 3Value: fourInput error. Try again. Value: 4Value: fiveInput error. Try again. Value:cinqInput error. Try again. Sum: 10.0I currently have:import java. io.*;import java. util.*;//import java. util. Scanner;public class DataReader{public static void main(String[] args){Scanner scan = new Scanner(System. in);boolean done = false;float sum = 0;String v;int count = 0;System. out. println("Please enter a number...");v = scan. next();while (!done){try{System. out. println("Value: " + v);float val = Float. parseFloat(v);sum = sum + val;done = true;}catch (NumberFormatException nfe){System. out. println("Input Error. Try again.");count++;if (count >= 2){done = false;}}//val = scan. nextFloat();System. out. println("Sum: " + sum);}}}

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 18:30
Which cultural aspect does this type of song best portray? a german polka dance
Answers: 1
question
Computers and Technology, 23.06.2019 12:00
What does the level 1 topic in a word outline become in powerpoint? a. first-level bullet item b. slide title c. third-level bullet item d. second-level bullet item
Answers: 1
question
Computers and Technology, 23.06.2019 15:00
Idon’t understand the double8 coding problem. it is java
Answers: 1
question
Computers and Technology, 24.06.2019 00:40
Use a software program or a graphing utility with matrix capabilities to solve the system of linear equations using an inverse matrix. x1 + 2x2 − x3 + 3x4 − x5 = 6 x1 − 3x2 + x3 + 2x4 − x5 = −6 2x1 + x2 + x3 − 3x4 + x5 = 3 x1 − x2 + 2x3 + x4 − x5 = −3 2x1 + x2 − x3 + 2x4 + x5 = 5
Answers: 3
You know the right answer?
Write a program that asks the user to input a set of floating-point values. When the user enters a v...
Questions
question
Mathematics, 29.06.2019 18:30
question
History, 29.06.2019 18:30
Questions on the website: 13722363