p3.java
p3.java
Class:Co4k(B)
Roll no:-64
Sub:-java programming(314317)
Practical no:-3
*if statement
Code:-
public class is
{
public static void main(String[] args)
{
int x = 10;
if (x < 20)
{
System.out.println("x is less than 20.");
}
}
}
Output:-
*If else statement
Code:-
public class st
{
public static void main(String[] args)
{
int number = 10;
if (number % 2 == 0)
{
System.out.println(number + " is even.");
}
else
{
System.out.println(number + " is odd.");
}
}
}
Output:-
*Nested if statement
public class nested
{
public static void main(String[] args)
{
int age = 20;
String citizenship = "Indian";
if (age >= 18)
{
if (citizenship.equals("Indian"))
{
System.out.println("You are eligible to vote in India.");
}
else
{
System.out.println("You are not eligible to vote in India.");
}
}
else
{
System.out.println("You are not eligible to vote due to age restrictions.");
}
}
}
Output:-
* if else ladder
Code:-
public class ifelselader
{
public static void main(String args[])
{
int x = 30;
if (x == 10)
{
System.out.println("Value of x is 10");
}
else if (x == 20)
{
System.out.println("Value of x is 20");
}
else if (x == 30)
{
System.out.println("Value of x is 30");
} else
{
System.out.println("This is else statement");
}
}
}
Output:-
*Switch case statement
Code:-
public class switchs
{