Lab 2

Lab Description:

For this lab, I had to use Eclipse to create a script to prompt a user to enter numbers. The program will use the data and compute several statistics.  For my script, i used a do while loop which allow the user to keep entering numbers until they enter 0.

Code:

import java.util.Scanner;
public class lab2
{   
    static Scanner input = new Scanner (System.in);
    public static void main (String[] args)
    {

    double first;
    double last = 0;
    double max;
    double min;
    double a;
    double b;
    double c;
    double sum;
    double sum1 = 0;
    int total = 0;

    System.out.println("Enter Numbers (0 to finish)");
    	first = input.nextDouble();
     	min = first;
    	max = first;

	do {
		a = input.nextDouble();   
		b = a;
		c = a;
		if (a!=0){
			if(b >= max)
				max = b;
			if(c <= min)
				min = c;
		}
		if (a!=0)
			last = a;
  	    sum1 = sum1 + a;
  	    sum = sum1 + first;
  	    total++;;
  	} while (a!=0);

    System.out.println("First Number Entered: " + first);
    System.out.println("Last Number Entered: " + last);
    System.out.println("Total Numbers Entered: " + total);
    System.out.println("Maximum: " + max);
    System.out.println("Minimum: " + min);
    System.out.println("Total Sum: " + sum);
    System.out.println("Average: " + sum / total);
    }
}

Screenshots: