In java :
Write a program that will provide important statistics for the grades in a class. The program will utilize a for-loop to read ten floating-point grades from user input. Include code to prevent an endless loop. Ask the user to enter the values, then print the following data:
Please let me know if anything is required
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
float sum=0,minimum=9999999,maximum=0; //initializing
the minimum , maximum and sum values
for(int i=0;i<10;i++) //loop for taking 10 grade
points and also calculating minimum,maximum and Average grade
points
{
System.out.print("Enter grade :
");
float myFloat = input.nextFloat(); //taking the grade
point from the user
sum = sum+myFloat; //calculating the sum of the all
grade points
if(myFloat<minimum) //checking if the grade point
is less than the minimum
{
minimum = myFloat; //if so then replacing the minimum
with the grade point
}
if(myFloat>maximum)//checking if the grade point is
greater than the maximum
{
maximum = myFloat; //if so then replacing the maximum
with the grade point
}
}
System.out.println("Maximum is " + maximum);
//printing the minimum of all grades
System.out.println("minimum is " + minimum);
//printing the maximum of all grades
System.out.println("Average is " + sum/10.0);
//printing the Average of all grades
}
}
Enter grade : 1.5 Enter grade : 2.5 Enter grade : 4.5 Enter grade : 3.5 Enter grade : 5.5 Enter grade : 7.5 Enter grade : 6.5 Enter grade : 8.5 Enter grade : 10.5 Enter grade : 9.5 Maximum is 10.5 minimum is 1.5 Average is 6.0
1 import java.util.Scanner; 3 public class Main public static void main(String[] args) { Scanner input = new Scanner(System.in); float arr[] = new float(10); //taking the float array to store the grade points float sum=,minimum=9999999, maximum 0; //initializing the minimum, maximum and sum values for(int i 0;i<10; i++) //loop for taking 10 grade points and also calculating minimum, maximum and Average grade points System.out.print("Enter grade : "); float myFloat = input.nextFloat(); //taking the grade point from the user arr[i] = myFloat; //storing the grade point into the array sum = sum myFloat; //calculating the sum of the all grade points if(myFloat minimum) //checking if the grade point is less than the minimum minimum = myFloat; //if so then replacing the minimum with the grade point Input Enter grade : 1.5 Enter grade : 2.5 Enter grade : 4.5 Enter grade : 3.5 Enter grade : 5.5 Enter grade : 7.5 Enter grade : 6.5
Get Answers For Free
Most questions answered within 1 hours.