Java program for nested if-else else if statement

Java program for nested if-else else if statement

A programming language uses control statements to control the flow of execution of program based on certain conditions.
you can use one if or else if statement inside another if or else if statement.



Nested else-if Program




if statements are executed from the top towards the bottom. As soon as the test expression is true, codes inside the body of that the if statement is executed. Then, the control of the program jumps outside the if-else-if ladder.
If none of the conditions is true, then the final else statement will be executed.
The final else acts as a default condition; that is, if all other conditional tests fail, then the last else statement is performed.


A  program construct that is based upon a sequence of nested with if-else-if ladder


import java.util.Scanner;
class Story
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the Number:");
int a=sc.nextInt();
if(a%3==0&&a%5==0)
System.out.println("Virat WEDS Anushaka");
else if(a%3==0)
System.out.println("Virat");
else if(a%5==0)
System.out.println("Anushaka");
else
System.out.println("BREAKUP");
}
}


Comments

Popular posts from this blog

Java Program for shop Bill to Calculate total amount of product with discount

RCM|Consequences of imbalanced Nutrition|WHO share daily need

Learn Data structures and algorithms concepts free online with certificate