Question
in this exercise we'll be using a slightly different combination of things we've worked on before, starting from scratch again. No individual element here is
in this exercise we'll be using a slightly different combination of things we've worked on before, starting from scratch again. No individual element here is new, so read the instructions carefully and break the task down into steps.
In the skeleton you are given a class ThreeNumbers which starts with an array called num, and little else.
Below the indicated comment you need to do the following (you may want to think about the order):
Create a standard main method. In the main method you need to:
Create a Scanner object to be used to read things in
Print a prompt to "Enter the first number: ", without a new line after it.
Read an int in from the user and store it as the first element of num.
Print a prompt to "Enter the second number: ", without a new line after it.
Read an int in from the user and store it as the second element of num.
Print a prompt to "Enter the third number: ", without a new line after it.
Read an int in from the user and store it as the third element of num.
Print "The sum of the three numbers is
.", with a new line after it, where is replaced by the actual sum of the elements of num. Print "The average of the three numbers is
.", with a new line after it, where is replaced by the actual average (rounded down, so you can use integer division) of the the elements of num.
Remember that computers aren't clever, so note the formatting and punctuation, especially in the feedback of the tests.
Note also that part of the task is to use the array num. Although you can print out the correct things without it, you cannot pass the task.
import java.util.Scanner;
/*
* @author Raymond Lister
* @version March 22, 2015
*/
class ThreeNumbers
{
static int [] num = {0, 0, 0};
// DO NOT CHANGE ANYTHING ABOVE THIS COMMENT LINE
//Create a main method
//Create a Scanner
//Prompt the user as per the description and read in an int.
//Prompt the user as per the description and read in another int.
//Prompt the user as per the description and read in the third int.
//Calculate the sum.
//Calculate the average.
//Print out the messages about the sum and average.
//Don't forget to put a closing brace at the end of the main method.
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started