recent

Java nested if else program

Nested If Else program java
/*nested if else means that you can use if else statements in any if or else block*/
import java.util.Scanner;

class JavaCondition {
  public static void main(String[] args) {
    int marksScored, passingMarks;
    char grade;

    passingMarks = 40;

    Scanner input = new Scanner(System.in);

    System.out.println("Enter marks scored by you");
 marksScored = input.nextInt();

    if (marksScored >= passingMarks) {

      if (marksScored > 90)
        grade = 'AA';
      else if (marksScored > 85 && marksScored <90)
        grade = 'AB';
      else if (marksScored > 75 && marksScored < 85)
        grade = 'BB';
      else if (marksScored > 65 && marksScored < 75 )
        grade = 'BC';
     else if (marksScored > 55 && marksScored < 65)
        grade = 'CC';
     else if (marksScored > 45 && marksScored < 55)
        grade = 'CC';
      else
        grade = 'D';

      System.out.println("You passed in exam and your grade is " + grade);
    }
    else {
      grade = 'F';
      System.out.println("You failed and your grade is " + grade);
    }
  }
}
Powered by Blogger.