Java if-else Statements

Java if else statements is used to execute some code, if a condition is true otherwise if condition is false, execute nothing, or execute some other code.
Syntax:
if(condition)
{
   //execute your code
}
else
{
   //execute your code
}
java-if-else
Example:
public class Sample {

    public static void main(String args[]) {
        int a = 80, b = 30;

        if (b > a) {
            System.out.println("b is greater");
        }
        else {
            System.out.println("a is greater");
        }
    }
}
Program Output:

java-if-else-statements

No comments:

Post a Comment