In the Popular section choose: Java: A concurrent, class-based, statically typed object-oriented language.
Click the pencil icon next to your repl name.
In the Default name: input box type: InputOutput
Delete all the lines of code provided as an example.
Copy the InputOutput.java Template (Java) code (below)
Paste that code into your new InputOutput class in the editor
Change the @author put-your-lastname-here
Replace the blank on the Scanner
line with: Scanner(System.in)
After the // add a line here to output a message advising the user to enter 9999 to exit
comment line add: System.out.println( "Enter '9999' to exit" ); // informs user how to exit
Replace the blank after the if (num == 9999) {
line with: break;
Replace the blank on the if ()
line with: cnt > 0
Replace the blank on the ave =
line with: sum / (double) cnt;
Replace the blank after the } else {
line with: ave = 0;
Click the Run icon
InputOutput.java Template (Java)
/**
* File: InputOutput.java
*
* Write a program that accepts 10 integers from the keyboard and
* computes their average.
* If the user enters 9999, the program exits early, and outputs
* the average of the numbers entered so far.
*
* Fill in the blanks to make the program work
*
*/
/**
*
* @authorput-your-name-here
*
*/import java.util.Scanner;
public class Main {
public static void main( String args[] ) {
doubleave = 0, cnt = 0, num = 0, sum = 0;
Scannersc = new_____________;
System.out.println("Integer Averaging Program");
System.out.println("Enter 10 Integers");
// add a line here to output a message advising the user to enter 9999 to exit______________// prompt the user for up to 10 integersfor ( int i = 1; i < 11; i++ ) {
System.out.print("Enter Integer " + i + ": ");
// check if the user entered a non-integerif (!sc.hasNextInt()) {
// System.err will print the message in RED
System.err.println("Sorry, please enter an integer");
sc.nextLine();
i--;
continue;
}
num = sc.nextInt();
// break out of the loop if the exit code (9999) is enteredif (num == 9999) {
__________
}
cnt++;
sum = (double) sum + (double) num;
}
// check to make sure the count is not set to zero since you can not divide by zeroif (__________ ) {
ave = _____________;
} else {
// if the count is zero then the program sets the average equal to zero____________;
}
System.out.println("The average of "
+ cnt
+ " numbers is "
+ ave );
sc.close();
}
}
InputOutput Class Output
Integer Averaging Program
Enter 10 Integers
Enter 9999 to exit
Enter Integer 1: kSorry, please enter an integer
Enter Integer 1: 55
Enter Integer 2: 66
Enter Integer 3: 77
Enter Integer 4: 88
Enter Integer 5: 9999
The average of 4.0 numbers is 71.5