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 07:00
Our primary purpouse as electricians is to do wich of the following core concepts? a: install electrical components in a way they can be upgraded b: install electrical equiptment in a way that reduces heat c: install electrical systems in a safe manner d: only b and c
Answers: 1
question
Computers and Technology, 22.06.2019 16:20
It policy compliance and emerging technologies respond to the following: propose at least three control measures that organizations need to put in place to ensure that they remain complaint with emerging technologies and in a continually changing it environment. examine the correlation of effective configuration management and change control procedures to remain compliant with emerging technologies and it security changes.
Answers: 2
question
Computers and Technology, 22.06.2019 17:00
Your company has 1,500 desktop computers running windows 7. you want to upgrade them to windows 10. which type of microsoft license would be best suited in this situation?
Answers: 3
question
Computers and Technology, 23.06.2019 07:30
What is the penalty for violating section 1201 of title 17 chapter 21 of the us code
Answers: 1
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, 02.07.2020 14:01
question
Mathematics, 02.07.2020 15:01
question
Mathematics, 02.07.2020 15:01
Questions on the website: 13722359