Hey guys, I'm not sure how to write the implementation plan to program 5 in
ID: 3630179 • Letter: H
Question
Hey guys, I'm not sure how to write the implementation plan to program 5 in java (the grading one) can someone please help me get started??"Write a program to read a list of non negative integers, and to display the largest integer, smallest integer, and the average of all the integers. The user indicates the end of the input by entering a negative sentinel value that is not used in finding the largest, smallest, and average values. The average should be a value type DOUBLE so that it is computed with a fractional part." This program should focus on the use of loops and nested branches.
Explanation / Answer
import java.util.Scanner;
public class Numbers
{
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
double number,large,small,sum=0;
int count=0;
double average;
//Create a scanner class for keyboard input
Scanner keyboard = new Scanner(System.in);
//Get numbers in series order
System.out.println("Enter numbers in a series:");
number = keyboard.nextInt();
large=small=number;
while(number!=-99)
{
number = keyboard.nextInt();
if(number==-99)
break;
if(number>large)
large=number;
if(number<small)
small=number;
sum+=number;
count++;
}
//Display largest number
System.out.println("Largest number is:"+ large);
//Display small number
System.out.println("Smallest number is:"+ small);
average=(sum/count);
System.out.println("Average:"+average);
//exit program
System.exit(0);
}
}