Friday, December 23, 2011

Program to


import java.util.*;
public class Ch2Q30
{
    public static void main(String[] args)
    {double no, max, min, sum;
    int count;
    Scanner kbd = new Scanner(System.in);
    System.out.print("Enter a number: ");
    no = kbd.nextDouble();
    if(no < 0)
       System.out.println("No data");
    else {count = 1; max = min = sum = no;
          System.out.print("Enter a number: ");
          no = kbd.nextDouble();
          while(no >= 0)
               {if(no > max)
                max = no;
                else if(no < min)
                   min = no;
                sum += no; count++;
                System.out.print("Enter a number: ");
                no = kbd.nextDouble();
               }
          System.out.println("Maximum = "+max+"\nMinimum = "+min);
          System.out.println("Average = "+ sum / count);
            }
     }
}

No comments:

Post a Comment