Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Design Implementation And Management

Authors: Carlos Coronel, Steven Morris

14th Edition

978-0357673034

More Books

Students also viewed these Databases questions