Home / Programs / If-else Statement in java
🚀 Programming Example

If-else Statement in java

👁 1,887 Views
💻 Practical Program
📘 Step Learning
If-else Statement in java

💻 Program Code

<code><font  size=2 face="Consolas"><font color="#FF0000"><b>public class </b></font><font color="#0066CC"><b>IfExample </b></font><b>{
</b><font color="#FF0000"><b>public </b></font><font color="#800000"><b>static void </b></font><font color="#0066CC"><b>main</b></font><b>(</b><font color="#0066CC"><b>String</b></font><b>[] </b><font color="#0066CC"><b>args</b></font><b>)
   {
    </b><font color="#800000"><b>int </b></font><font color="#0066CC"><b>age</b></font><b>=</b><font color="#FF0000"><b>20</b></font><b>;
    </b><font color="#FF0000"><b>if</b></font><b>(</b><font color="#0066CC"><b>age</b></font><b>&gt;</b><font color="#FF0000"><b>18</b></font><b>){
        </b><font color="#0066CC"><b>System</b></font><b>.</b><font color="#0066CC"><b>out</b></font><b>.</b><font color="#0066CC"><b>println</b></font><b>(&quot;Age is greater than 18&quot;);
      }
   }
}
</b></font>
</code>
                        

🖥 Program Output

Age is greater than 18
Press any key to continue . . .
                            
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.