How do I make the code read different inputs, after it has done one? Input: 25 75 -1 5 10 20 30 40 50 60 70 80 90 100 -1 19 15 14 33 76 46 88 78 69 79 75 73 72 -1 -1 Only inputs: 25 75 -1 Code: import java.util.Scanner; public class Grades { public static void main(String[] args) { //Declare required variables int grade,count = 0; int min = 100, max = 0; //Scanner for user input Scanner scan = new Scanner(System.in); //Infinite loop while(true) { //Prompt for input System.out.println("Enter a grade : "); grade = scan.nextInt(); if(grade<0) break; else count++; //Keep track of grades max = Math.max(max, grade); min = Math.min(min, grade); } //Output result System.out.println("Number Of Grades = " + count); System.out.println("Maximum Grade = " + max); System.out.println("Minimum Grade = " + min); System.out.println(""); } }
How do I make the code read different inputs, after it has done one?
Input:
25 75 -1
5 10 20 30 40 50 60 70 80 90 100 -1
19 15 14 33 76 46 88 78 69 79 75 73 72 -1 -1
Only inputs:
25 75 -1
Code:
import java.util.Scanner;
public class Grades {
public static void main(String[] args) {
//Declare required variables
int grade,count = 0;
int min = 100, max = 0;
//Scanner for user input
Scanner scan = new Scanner(System.in);
//Infinite loop
while(true) {
//Prompt for input
System.out.println("Enter a grade : ");
grade = scan.nextInt();
if(grade<0)
break;
else
count++;
//Keep track of grades
max = Math.max(max, grade);
min = Math.min(min, grade);
}
//Output result
System.out.println("Number Of Grades = " + count);
System.out.println("Maximum Grade = " + max);
System.out.println("Minimum Grade = " + min);
System.out.println("");
}
}
Step by step
Solved in 4 steps with 3 images