Question

Step 1: Write a Java program that finds the sum of 10 numbers entered by the...

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.

Homework Answers

Answer #1
//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));
    }
}
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
In Java, Write a small program that gets some numbers as command line arguments and finds...
In Java, Write a small program that gets some numbers as command line arguments and finds the minimum of those numbers. You can assume that the user will provide some command line arguments when running the program (so you don’t have to worry about what to do if the user doesn’t provide any arguments -- that won’t happen). Also, you can assume that all the command line arguments will be floating-point numbers, i.e., numbers with a decimal point, like 8.25.
The Java program should sum the odd integers from 1 to the integer that the user...
The Java program should sum the odd integers from 1 to the integer that the user enters. For example, if the user enters 30, the program should sum the odd integers from 1 to 30.   Print "Please enter a positive nonzero integer." Declare a Scanner and obtain an integer from the user.   Use a Do...while statement and calculate the sum Use the integer that the obtained from the previous step for the loop-continuation condition. Display the sum Print the sum...
Write a function that takes two integer inputs and returns the sum of all even numbers...
Write a function that takes two integer inputs and returns the sum of all even numbers between these inputs, and another function that takes two integer inputs and returns the sum of odd numbers between these inputs .In main function, the program will asks the user to enter two integer numbers and then passes them to these two functions and display the result of each of them.         [0.5 mark] (BY USING C PROGRAM)
Use C++ Write a program that first reads in how many whole numbers the user wants...
Use C++ Write a program that first reads in how many whole numbers the user wants to sum, then reads in that many whole numbers, and finally outputs the sum of all the numbers greater than zero, the sum of all the numbers less than zero (which will be a negative number or zero), and the sum of all the numbers, whether positive, negative, or zero. The user enters the numbers just once each and the user can enter them...
c++ Write a program that calls a function calculateSum to calculate the sum from -1 to...
c++ Write a program that calls a function calculateSum to calculate the sum from -1 to N. The function calculateSum has one parameter N of type integer and returns an integer which represents the sum from -1 to N, inclusive. Write another function calculateAverage that calculates an average. This function will have two parameters: the sum and the number of items. It returns the average (of type float). The main function should be responsible for all inputs and outputs. Your...
[Java] Write a program that stores pairs of all the states and capitals (USA). The program...
[Java] Write a program that stores pairs of all the states and capitals (USA). The program should give the user a State and ask for the capital. The program should keep track of how many correct answers were given. User should see score printed at the end. IMPORTANT: Make sure the program RANDOMLY asks for the capital of a random state. This question has already been asked before in Expert Q&A but the answer never randomly gave states.
1)Write a program that asks a user for a number. If (and only if) the number...
1)Write a program that asks a user for a number. If (and only if) the number is greater than zero print “The number is valid” 2)Write a program that asks a user for a grade. If (and only if) the grade is greater than zero and less than 101, print “The grade is valid” 3)Write a program that asks a user how many widgets they want to buy and prints out what the user should pay. Widgets costs 10 dollars....
Write a Python program which calculates the average of the numbers entered by the user through...
Write a Python program which calculates the average of the numbers entered by the user through the keyboard. Use an interactive loop and ask the user at each iteration if he/she wants to enter more numbers. At the end dispay the average on the screen. Using built-in library functions for finding average is not allowed. Sample output of the program: Enter a number > 23 More numbers (yes or no)? y Enter a number > 4 Do you have more...
Please use Python 3 4). Write a program that asks the user to enter 10 numbers....
Please use Python 3 4). Write a program that asks the user to enter 10 numbers. The program should store the numbers in a list and then display the following data: • The lowest number in the list • The highest number in the list •The total of the numbers in the list • The average of the numbers in the list   Sample input & output: (Prompt) Enter Number 1: (User enter) 4 (Prompt) Enter Number 2: (User enter) 7...
B.2. Write a Java program to display a dialog box that asks you to enter your...
B.2. Write a Java program to display a dialog box that asks you to enter your user name and the age as shown below: The program displays in a dialog box the sum of digits of your age. For example, if you age is 19, the sum will be 1+9 = 10 and the output will be as shown below: ( it just shows a message box that says the sum of the digits age of john is 10.