Lab 1

LAB 1

This Lab was extremely mind blowing. it took forever to solve because of my lack of Java knowledge but with the help my class mates and a lot of reading, we were able to get Lab 1 running. this was a great lab to really understand the complexity and the simplicity all in one Lab. This Lab has made me understand how this Java program works and I’m very interested how Lab 2 will be.

Program

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner input = new Scanner(System.in);
		//declaration
		int count=1;
		int num=0;
		int max=0;
		int min = 0;
		int first=0;
		int last=1;
		double sum=0;
		double avg=0;
		System.out.print("Enter any amount of numbers:\n");
		System.out.println("Enter 0 to exit");
		first = input.nextInt();

		min = num;
		//while loop
		while(true){

			num = input.nextInt();

			if (num ==0) break;

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

				if ((num < first) && (num !=0)){
					min = num;
				}
				else if (num < min){ 					min = num; 				} 			if (num >=0){
				last=num;
			}

			sum=num+sum;
			count++;
		}
		sum = sum + first;
		avg= sum/count;

		System.out.printf("the First number is:  %d\n",first);
		System.out.printf("the Last number is:   %d\n", last);
		System.out.printf("the Count of number entered %d\n",count);
		System.out.printf("the Minimum: %d\n",min);
		System.out.printf("the Maximum: %d\n",max);
		System.out.printf("the Sum of all numbers is: "+sum+ "\n");
		System.out.printf("the Average of total numbers is: "+avg);

		input.close();
	}

}

Screen Shot

Lab 1

Leave a Reply

Your email address will not be published. Required fields are marked *