Java If ... Else | |||
![]() ![]() ![]() | |||
You already know that Java supports the usual logical conditions from mathematics:
You can use these conditions to perform different actions for different decisions. Java has the following conditional statements:
The if Statement Use the
In the example below, we test two values to find out if 20 is greater than 18. If the condition is
We can also test variables:
In the example above we use two variables, x and y, to test whether x is greater than y (using the The else Statement Use the
Example
In the example above, time (20) is greater than 18, so the condition is The else if Statement Use the
Example
In the example above, time (22) is greater than 10, so the first condition is However, if the time was 14, our program would print “Good day.” Tags: Java Java else Java if else if ![]() ![]() | |||
| |||
| |||
|
SIMILAR POSTSJava Short Hand If...Else (Ternary Operator)Java Switch StatementsJava While Loop/Do While Loop/For Loop/For-Each Loop/Break/ContinueJava MathJava VariablesJava CommentsJava MethodsJava ScopeJava RecursionThe Print() MethodJava SyntaxJava Classes and ObjectsJava Getting StartedJava PackagesJava Inheritance (Subclass and Superclass)Java PolymorphismJava Inner ClassesWhat is Java?Machine Learning Types and Programming LanguagesJava Tutorials associated with AP Computer Science ACreating a simple Java Servlet (Web Server Page) with Apache Maven on Microsoft WindowsJava Servlet ExampleDifference between Java and Javascript |
OTHER POSTS IN THE SAME CATEGORYDataset of California FoodbanksJava Tutorials associated with AP Computer Science AJava Inner ClassesJava PolymorphismJava Inheritance (Subclass and Superclass)Java PackagesJava Abstract Classes and MethodsJava Classes and ObjectsJava RecursionJava ScopeJava MethodsJava ArraysJava While Loop/Do While Loop/For Loop/For-Each Loop/Break/ContinueJava Switch StatementsJava Short Hand If...Else (Ternary Operator)Java MathJava VariablesJava CommentsThe Print() MethodJava SyntaxJava Getting StartedWhat is Java? |