import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
try
{
double sum = 0;
double number, avg;
Scanner input = new Scanner(System.in);
System.out.println("Enter numbers:");
for(int i=0; i<10; i++)
{
number = input.nextDouble();
sum += number;
}
avg = sum/10.00;
System.out.println("Sum is: " + sum + "\n" + "Average is: " + avg);
} catch(Exception e)
{
System.out.println("oops! You must enter a number...");
}
}
}
A simple Java code to calculate the average of 10 numbers.
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.