Question: Java Project The bold line needs to be formatted to match the procedure instructions Procedure 1. Output the count in a two column decimal format

Java Project

The bold line needs to be formatted to match the procedure instructions

Procedure

1. Output the count in a two column decimal format (%2d)

2. Output the integer in a 5 column decimal format (%5d)

3. Output the running total in a 15 column decimal format (%15d)

4. Remember to change your println to printf to allow formatting

5. Add a blank println statement after the printf, so that a new line is issued

6. Add a declaration for a double variable and use it to hold the calculated average

7. Be sure to cast your average calculate as a double so that a double value is generated

8. Output the average using a format of 15 characters, 2 decimal places (%15.2f)

PROJECT CODE HERE:

/* *This program will prompt for a list of numbers and add each number to a running total * sentinel controlled loop */ import java.util.Scanner; public class Main {

public static void main(String[] args) { // instantiate scanner object to read input Scanner input = new Scanner(System.in); final int ENDRUN = -99; // set up value to end run int sum = 0; // initialize running total to zero int count = 0; // initialize count of integers to zero System.out.println("Enter a valid integer"); // prompt for integer System.out.print("Enter " + ENDRUN + " to end: "); // reminder about sentinel value int number = input.nextInt(); // use scanner to read an integer - priming read while (number != ENDRUN) { // if number was not sentinel sum += number; // add it to the running total count++; System.out.println("Added " + number + " to sum. Running total is now " + sum); // output the number and running total System.out.println("Enter a valid integer"); System.out.print("Enter " + ENDRUN + " to end: "); number = input.nextInt(); // read next number or sentinel } // end of while System.out.println("The average of the entered numbers is: " + (sum/count)); } // end of main method } // end of Main class

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!