I have written this switch case program in Java. However, the while loop is not breaking out. Here's the code:
import java.util.Scanner;
public class exam001 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int marks;
while(true) {
System.out.println("This is a gade checker program");
System.out.println("Enter the marks from 0 to 100: ");
System.out.println("Enter the marks: ");
marks = scanner.nextInt();
int grade = marks / 10;
if (marks > 100) {
System.out.println("Please enter the marks between the limit assigned");
}
else {
switch(grade) {
case 10:
case 9:
System.out.println("Your grade is A");
break;
case 8:
case 7:
System.out.println("Your grade is B");
break;
case 6:
System.out.println("Your grade is C");
break;
case 5:
case 4:
System.out.println("Your grade is D");
break;
default:
System.out.println("Your grade is E");
break;
}
}
}
}
}
I dont know, why the break function is not working in this loop.. Please help me..