In: Computer Science
Code
public class Main
{
public static void main(String[] args) {
int sum = 0;
double average;
int i = 0;
// Reading 10 integers as strings and adding
// into sum after conversion from string to int
while(i< 10)
{
String value = System.console().readLine();
try
{
sum = sum + Integer.parseInt(value);
}
catch(Exception NumberFormatException )
{
System.out.println("Please enter the valid
number\n");
continue; // Again asking for number so skipping
increment of i
}
i++;
}
average = (double)sum/10;
System.out.printf("average is: %f",
average);
}
}
Sample Output