This post contains some examples related to if-else Decision Making in Java. Decision-making is one of the basic and important concepts not in Java but in any programming. The if statement tells us that if a condition is true and it will execute a block of code and if the condition is false it won’t. But what if we want to do something else if the condition is false. Here comes the else statement.
We can use the else statement with if statement to execute a block of code when the condition is false. Now it's a time to watch some examples related to the if-else Decision making in Java
Examples
1. Check whether the input given by the users is suitable for finding the Area of the Rectangle.
If Length>Breadth
Length: 8
Breadth: 4
Code
Output
Enter the Length Measurement
8
Enter the Breadth Measurement
4
Area of the Rectangle is: 32
If Length<Breadth
Length: 4
Breadth: 8
Code
Output
Enter the Length Measurement
4
Enter the Breadth Measurement
8
Please Enter the valid Dimensions for the Rectangle as per the values assigned
0 Comments