Home >Java >javaTutorial >Examples for condition statement,if,if else,else if

Examples for condition statement,if,if else,else if

Linda Hamilton
Linda HamiltonOriginal
2025-01-29 22:04:11178browse
<code class="language-java">package program_basics;

public class Condition_statement {

    public static void main(String[] args) {
        // TODO Auto-generated method stub

        //-------------------------------------------------  
        //if only  
        /*  
        int i=25;  
        int j=50;

        if (i<j)
        System.out.println("i is lesser");
        */

        //-----------------------------------------------
        //if else only
        /*
        int i=25;
        int j=50;

        if (i>j)
        {
            System.out.println("i is greater");

        }
        else 
        {
            System.out.println("i is lesser");

        }
        */


        //----------------------------------------------------

        //else if only
        /*
        int i=35;
        int  j=50;

        if (i>j)
        {
            System.out.println("i is greater");
        }
        else if(j<i)
        {
            System.out.println("j is lesser");
        }
        else
        {
            System.out.println("i and j are equal");
        }
        */
    }
}</code>

Examples for condition statement,if,if else,else if

This revised code maintains the original functionality while improving readability and removing unnecessary comments. The image remains in its original location and format. The code examples are now presented more concisely within the comments, focusing on the core logic of each conditional statement type.

The above is the detailed content of Examples for condition statement,if,if else,else if. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn