Step 1: Write a Java program that finds the sum of 10 numbers entered by the user.
Step 2: Modify the previous program so that it asks the user how many numbers they have, inputs that many numbers, and finally outputs the average of their numbers. The messages to the user should be clear throughout.
//Sum10.java import java.util.Scanner; public class Sum10 { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int sum = 0; for(int i = 0;i<10;i++){ System.out.print("Enter number: "); sum += scan.nextInt(); } System.out.println("Sum: "+sum); } }
/////////////////////////////////////////////////////////////////
//Average10.java import java.util.Scanner; public class Average10 { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int sum = 0; for(int i = 0;i<10;i++){ System.out.print("Enter number: "); sum += scan.nextInt(); } System.out.println("Average: "+(sum/10)); } }
Get Answers For Free
Most questions answered within 1 hours.