write a program in java for check number is one, two, three and more tha three digit. Using if else if
Answers
Answer:
If else statement in Java
This is how an if-else statement looks:
if(condition) { Statement(s); } else { Statement(s); }
The statements inside “if” would execute if the condition is true, and the statements inside “else” would execute if the condition is false.

Example of if-else statement
public class IfElseExample { public static void main(String args[]){ int num=120; if( num < 50 ){ System.out.println("num is less than 50"); } else { System.out.println("num is greater than or equal 50"); } } }
Output:
num is greater than or equal 50
if-else-if Statement
if-else-if statement is used when we need to check multiple conditions. In this statement we have only one “if” and one “else”, however we can have multiple “else if”. It is also known as if else if ladder. This is how it looks:
if(condition_1) { /*if condition_1 is true execute this*/ statement(s); } else if(condition_2) { /* execute this if condition_1 is not met and * condition_2 is met */ statement(s); } else if(condition_3) { /* execute this if condition_1 & condition_2 are * not met and condition_3 is met */ statement(s); } . . . else { /* if none of the condition is true * then these statements gets executed */ statement(s); }
Note: The most important point to note here is that in if-else-if statement, as soon as the condition is met, the corresponding set of statements get executed, rest gets ignored. If none of the condition is met then the statements inside “else” gets executed.
Example of if-else-if
public class IfElseIfExample { public static void main(String args[]){ int num=1234; if(num <100 && num>=1) { System.out.println("Its a two digit number"); } else if(num <1000 && num>=100) { System.out.println("Its a three digit number"); } else if(num <10000 && num>=1000) { System.out.println("Its a four digit number"); } else if(num <100000 && num>=10000) { System.out.println("Its a five digit number"); } else { System.out.println("number is not between 1 & 99999"); } } }