Java - If Else Grade Book 2
|
|
Change the code below from 5 if-statements to nested if-else statements (don't use &&):
if (...){
...
} else if (...){
...
} else if (...){
...
} else if (...){
...
} else {
...
}
if (...){
...
} else if (...){
...
} else if (...){
...
} else if (...){
...
} else {
...
}
// Get a grade from the keyboard
Scanner kbReader = new Scanner(System.in);
int theGrade;
System.out.print("What is your grade? ");
theGrade = kbReader.nextInt();
if (theGrade >= 90) {
System.out.println("You made an A.");
}
if (theGrade >= 80 && theGrade <= 89) {
System.out.println("You made a B.");
}
if (theGrade >= 70 && theGrade <= 79) {
System.out.println("You made a C.");
}
if (theGrade >= 65 && theGrade <= 69) {
System.out.println("You made a D.");
}
if (theGrade < 65) {
System.out.println("Sorry, you failed.");
}