In: Computer Science
For this portion of Lab #2, write a program that prompts the user to enter ten integer values between 1 and 100, determines the smallest and largest values entered by the user as well as the average of all the numbers entered by the user (expressed as a floating-point number), and then prints the smallest number, the largest number, and the average. Print each of these values with descriptive labels. Your program output should resemble the following (the user's input is shown in bold): Enter ten integers between 1 and 100, and I will tell you the smallest, the largest, and the average: 56 47 21 3 10 8 77 41 9 34 Smallest: 3 Largest: 77 Average: 30.6 NOTE: Your program should not read the ten numbers into ten separate integer variables, nor should it be necessary to use a data structure (such as an array) to store the numbers. Instead, use a loop which is set up to repeat ten times, and which determines the smallest and largest numbers seen so far, as the user enters each number. Remember also that you will need to add each number to a running total, in order to compute the average after all ten numbers have been entered. After you have completed your program, double-check your results by computing the smallest, largest, and average yourself, comparing your own results to those given by the program. Can someone help me with this java program
code:
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
//initializing variables
int n,sum = 0,smallest=101,largest=-1;
double avg;
System.out.println("Enter ten integers between 1 and 100 ");
//loop 10 times to read 10 numbers from user
for(int i=0;i<10;i++){
//get number from user
n = sc.nextInt();
//add value to sum
sum+=n;
//see if it is current smallest
if(n<smallest){
smallest = n;
}
//see if it is current largest
if(n>largest){
largest = n;
}
}
avg = (double)sum/10;
System.out.println("Smallest: "+smallest);
System.out.println("Largest: "+largest);
System.out.println("Average: "+avg);
}
}