0

ok i need a to make two simple programs from
The first program can be a while , for , switch, or a do while loop

1)
Output
This progeam allows you to enter a list of positive integers(terminated by a -1) then displays the largest value, smallest value, and average of the list of numbers, not including the final (negative) value that ends the list.

Please enter a positive integer, or a -1 to quit.
100
Please enter a positive integer, or a -1 to quit.
50
Please enter a positive integer, or a -1 to quit.
75
Please enter a positive integer, or a -1 to quit.
-1
For the 3 numbers you entered
the largest value = 100
the smallest value = 50
and the average is = 75

2) Else If Loop
Output

Enter the price of an item
(from 25 cents to a dollar in 5- cent uncremenst 
85
you bought an item for 85 cents and gave me a dollar
so your change is 
0 quarters 
1 dime and 
1 nickel

This is what i got for the first one

public class Project1
{
public static void main(String[] args)
{

System.out.println("This program allows you to enter a list of poistive integers");
System.out.println("(terminated by a -1) then displays the largest value, ");
System.out.println("smallest value, and average of the list of numbers, not");
System.out.println("including the final (negative) value that ends the list.");
System.out.println("");
int number;
System.out.println("PLease enter a positive integer, or a -1 to quit.")
number = SavitchIn.readlineInt();
}
}

This is all i got. i just started learning. The teacher had been absent and the teacher's aid (student teaching class) sucks. The only requirement is it has to have the output i wrote and has to be a while loop. If you could help it would be greatly appreciated. Than You.

Edited by mike_2000_17: Fixed formatting

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by javaAddict
0
number = SavitchIn.readlineInt();
int sum=0;
int count=0;
int tempMax=number;
int tempMin=number;
while ( number != -1 ) {
  //have an int variable(count) that increases by 1 each time, counting how many numbers   
  //were given

  //add each number to the sum variable in order to have the total sum

  //use the tempMax,tempMin in order to compare them with the new number given and    
  //change their values only if the new number is greater or lower than them

  number = SavitchIn.readlineInt();
}
int average = sum/count;
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.