Nested if-else Statement (Selection Statement)

Example 1

public class NestedIfElse_Example1 {
	public static void main(String[] args) {
		int x = 1000;
		int y = 150;
		int z = 200;
		if (x > y) {
			if (x > z) {
				System.out.println("x is greatest");
			}
		} else if (y > z) {
			System.out.println("y is greatest");
		} else
			System.out.println("z is greatest");
	}
}

Example 2

public class NestedIfElse_Example2 {
	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);
	}
}