LAB # 2

OBJECTIVES:

The objectives  of this laboratory experiment is to  be familiar with  java syntax. In this  experiment the user is allowed to enter as much numbers as possible. To  end the series of numbers the user will enter zero. Once the numbers are all entered  the program will display the  First number, Last number, The count of all numbers entered, Maximum and Minimum numbers and The Sum and Average of the sequence.

CODE:

 import java.util.Scanner;
public class Intro_to_java {
/**
* @param args
*/
@SuppressWarnings("resource")
public static void main(String[] args) {
// TODO Auto-generated method stub

Scanner input = new Scanner(System.in);

int first_num = 0;
int last_num = 0;
int num = 0;
int count = 0;
int max = 0;
int min = 0;
int total_sum = 0;
int avg = 0;

	while( true) {
	System.out.print("Enter numbers!");

	num = input.nextInt ();

		if (num == 0) break; // once 0 is entered the request of the input will end.

		if (count == first_num){
			first_num = num; // store the value of the first number that was entered
		}

		if (count > 0){
			last_num = num; // store the value of the last number entered
		}
		count++;

		if(num > max){
			max = num;
		}

		if(num < min){
			min = num;
		}

		total_sum = (num + total_sum);

		avg = (total_sum / count);

	}

	System.out.println("The First number entered is"+first_num);
	System.out.println("The Last number entered is"+last_num);
	System.out.println("The Count of numbers enterd is"+count);
	System.out.println("The Maximum number entered is"+max);
	System.out.println("The Minimum number entered is"+min);
	System.out.println("The Total sum is"+total_sum);
	System.out.println("The Average is"+avg);

}

}
 SCREENSHOT: