1.5.3 if else if Statement

Add to your Selection project:

if - else - if Demo

public class IfElseIfDemo { public static void main(String[] args) { int testscore = 76; char grade; if (testscore >= 90) { grade = 'A'; } else if (testscore >= 80) { grade = 'B'; } else if (testscore >= 70) { grade = 'C'; } else if (testscore >= 60) { grade = 'D'; } else { grade = 'F'; } System.out.println("Grade = " + grade); } }

  • You can have as many else if statements as needed.

source: Oracle site

Modify this program so that the test score is entered in a input dialog box