If and Else Statements
Learn how to make decisions in Java using if, else if and else.
Java Code
Study the example and understand what each part does.
public class Main {
public static void main(String[] args) {
int marks = 75;
if (marks >= 70) {
System.out.println("Excellent");
} else if (marks >= 50) {
System.out.println("Good");
} else {
System.out.println("Needs improvement");
}
}
}
Java code normally runs using the Java Development Kit on a computer, Android Studio or another Java development environment. This course page presents the code examples without pretending that the browser is running Java directly.
Expected Output / Result
Excellent
Finished this lesson?
Mark it complete to update your course progress.