Answer:
See Explaination for program code
Explanation:
Code below
import java.io.*;
import java.util.*;
// Declare a class
public class DataReader
{
// Start the main method.
public static void main(String[] args)
{
// create the object of scanner class.
Scanner scan = new Scanner(System.in);
// Declare variables.
boolean done = false;
boolean done1 = false;
float sum = 0;
double v;
int count = 0;
// start the while loop
while (!done1)
{
// start the do while loop
do
{
// prompt the user to enter the value.
System.out.println("Value:");
// start the try block
try
{
// input number
v = scan.nextDouble();
// calculate the sum
sum = (float) (sum + v);
}
// start the catch block
catch (Exception nfe)
{
// input a character variable(\n)
String ch = scan.nextLine();
// display the statement.
System.out.println(
"Input Error. Try again.");
// count the value.
count++;
break;
}
}
// end do while loop
while (!done);
// Check whether the value of count
// greater than 2 or not.
if (count >= 2)
{
// display the statement on console.
System.out.println("Sum: " + sum);
done1 = true;
}
}
}
}