Objective:
This lab is introducing us more into java, and the purpose of this lab is to get familiar with the syntax language. This lab consist of us writing a program were we allow the user to enter as many number as he/she pleases including negative/postive numbers and when they finish they just have to enter 0 to let the program know that they are finished entering the numbers
Conclusion:
unfortunately i was having alot of trouble doing this lab, and was doing some research to get my program to run but for some reason I am having alot of errors
Code:
import java.util.Scanner; public class Lab2 { public static void main(String[] args) { Scanner input = new Scanner(System.in); int num = 1; int max = 0; int min = 1; int totalnum = 0; int counter = 1; int numberAmount = 0; double average; int number = 1; int firstdigit = number; int lastdigit = number % 10; System.out.println(“Enter Series of numbers”); System.out.println(“Enter 0 when finished numbers”); do { number=input.nextInt(); int numberAmount = 0; numberAmount ++; totalnum = totalnum + number; if (number > max) { max=number; } counter=0; if(number==max) { counter++; } else if (number < min) { min=number; } counter=1; if(number==min) { counter ++; } } while (number !=0); average=(double)totalnum/(numberAmount-1); float is; System.out.println(“The average is %.2f\n”, average); System.out.println(“the total number you entered: ” + numberAmount); System.out.println(“The sum for the numbers you entered is ” + totalnum); System.out.println(“The maximum number is: ” + max); System.out.println(“The minimum number is: ” + min); System.out.println(“the first digit you entered is .” + firstdigit); firstdigit = counter - totalnum; } }