0% found this document useful (0 votes)
13 views

Programs on Conditional Statements

Uploaded by

singhshubh430
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Programs on Conditional Statements

Uploaded by

singhshubh430
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Programs on conditional statements

1)
class SimpleIf
{
public static void main(String[] args)
{
System.out.println("Program start");
int num=5;//10,5
if(num>=10)
{
System.out.println(num+" is >= 10");
}
System.out.println("Program end");
}
}

Output
Program start
Program end
2)
class SimpleIf1
{
public static void main(String[] args)
{
System.out.println("Program start");
int age=20;
if(age>=18)
{
System.out.println("person is eligible for vote");
}
System.out.println("Program end");
}
}

Output
Program start
person is eligible for vote
Program end
3)
class IfElse
{
public static void main(String[] args)
{
int n=5;

if(n>=10)
{

System.out.println(n + " is >= 10");


}
else{

System.out.println(n + " is < 10");


}
}
}

Output
5 is < 10
4)
class IfElse2
{
public static void main(String[] args)
{
int age = 15;
if(age >= 18)
{
System.out.println("Person is eligible for vote");
}
else
{
System.out.println("Person is not eligible for vote");
}
}
}

Output
Person is not eligible for vote
5)
class IfElseIf
{
public static void main(String[] args)
{
int a = 20;
int b=100;
if(a>b)
{

System.out.println(a+ " is > then "+b);


}
else if(a==b)
{
System.out.println(a+ " is == "+b);
}
else{
System.out.println(a+ " is < then "+b);
}
}
}

Output
20 is < then 100
6)
class Result
{
public static void main(String[] args)
{
System.out.println("Program start");

char grade = 'B';

switch(grade)
{
case 'A' : System.out.println("Excellent");

break;

case 'B' : System.out.println("Good");


break;

case 'C' : System.out.println("Average");


break;

case 'D' : System.out.println("Fail");


break;

default : System.out.println("Invalid grade");


break;
}
System.out.println("Program end");
}
}
Output
Program start
Good Program
end
7)
class GmailLogin
{
public static void main(String[] args)
{
String user_Id = "Smith123";

String pwd = "Smi@123";

if(user_Id == "Smith123")
{
if(pwd == "Smi@123")
{

System.out.println("login successfull");
}
else{
System.out.println("invalid pwd");
}

else{
System.out.println("invalid userid");
}
}
}
Output
login successfull

You might also like