Opening Hours :7AM to 9PM
if(Condition)
{
..
..
..
}
'if else' is a keyword in java language .Which is used to execute one block of statements between two blocks
Syntax:
if(Condition)
{
..
..
}
else
{
..
..
}
class Main
{
public static void main(String args[])
{
int x=10;
if(x%2==0)
{
System.out.println("Even Number");
}
else
{
System.out.println("Odd Number");
}
}
}
class Main
{
public static void main(String args[])
{
int x;
x=Integer.parseInt(args[0]);
if(x%2==0)
{
System.out.println("Even Number");
}
else
{
System.out.println("Odd Number");
}
}
}
import java.util.*;
class Main
{
public static void main(String args[])
{
int x;
Scanner s=new Scanner(System.in);
System.out.println("Enter x Value");
x=s.nextInt();
if(x%2==0)
{
System.out.println("Even Number");
}
else
{
System.out.println("Odd Number");
}
}
}
class Main
{
public static void main(String args[])
{
int x=10,y=20;
if(x>y)
{
System.out.println("x is Max");
}
else
{
System.out.println("y is Max");
}
}
}
class Main
{
public static void main(String args[])
{
int x,y;
x=Integer.parseInt(args[0]);
y=Integer.parseInt(args[0]);
if(x>y)
{
System.out.println("x is Max");
}
else
{
System.out.println("y is Max");
}
}
}
import java.util.*;
class Main
{
public static void main(String args[])
{
int x,y;
Scanner s=new Scanner(System.in);
System.out.println("Enter x ,y values");
x=s.nextInt();
y=s.nextInt();
if(x>y)
{
System.out.println("x is Max");
}
else
{
System.out.println("y is Max");
}
}
}
if(Condition)
{
..
..
}
else if(Condition)
{
..
..
}
else if(Condition)
{
..
..
}
else if(Condition)
{
..
..
}
..
..
else
{
..
..
}
class Main
{
public static void main(String args[])
{
int age=24;
if(age>=0 && age<=12)
{
System.out.println("You are a child");
}
else if(age>=13 && age<=19)
{
System.out.println("You are a teenager");
}
else if(age>=20 && age<=45)
{
System.out.println("You are younger");
}
else if(age>=46 && age<=80)
{
System.out.println("You are old");
}
else if(age>=81 && age<=100)
{
System.out.println("You are too old");
}
else if(age>=101)
{
System.out.println("Invalid");
}
else
{
System.out.println("Age should not be negative");
}
}
}
class Main
{
public static void main(String args[])
{
int age;
age=Integer.parseInt(args[0]);
if(age>=0 && age<=12)
{
System.out.println("You are a child");
}
else if(age>=13 && age<=19)
{
System.out.println("You are a teenager");
}
else if(age>=20 && age<=45)
{
System.out.println("You are younger");
}
else if(age>=46 && age<=80)
{
System.out.println("You are old");
}
else if(age>=81 && age<=100)
{
System.out.println("You are too old");
}
else if(age>=101)
{
System.out.println("Invalid");
}
else
{
System.out.println("Age should not be negative");
}
}
}
import java.util.*;
class Main
{
public static void main(String args[])
{
int age;
Scanner s=new Scanner(System.in);
System.out.println("Enter Your age");
age=s.nextInt();
if(age>=0 && age<=12)
{
System.out.println("You are a child");
}
else if(age>=13 && age<=19)
{
System.out.println("You are a teenager");
}
else if(age>=20 && age<=45)
{
System.out.println("You are younger");
}
else if(age>=46 && age<=80)
{
System.out.println("You are old");
}
else if(age>=81 && age<=100)
{
System.out.println("You are too old");
}
else if(age>=101)
{
System.out.println("Invalid");
}
else
{
System.out.println("Age should not be negative");
}
}
}
if(condition)
{
if(condition)
{
..
..
}
else
{
..
..
}
}
else
{
..
..
..
}
class Main
{
public static void main(String args[])
{
int x=10;
if(x>0)
{
if(x%2==0)
{
System.out.println("Even Number");
}
else
{
System.out.println("Odd Number");
}
}
else
{
System.out.println("Pls Enter Positive Number");
}
}
}
class Main
{
public static void main(String args[])
{
int x;
x=Integer.parseInt(args[0]);
if(x>0)
{
if(x%2==0)
{
System.out.println("Even Number");
}
else
{
System.out.println("Odd Number");
}
}
else
{
System.out.println("Pls Enter Positive Number");
}
}
}
import java.util.*;
class Main
{
public static void main(String args[])
{
int x;
Scanner s=new Scanner(System.in);
System.out.println("Enter x Value");
x=s.nextInt();
if(x>0)
{
if(x%2==0)
{
System.out.println("Even Number");
}
else
{
System.out.println("Odd Number");
}
}
else
{
System.out.println("Pls Enter Positive Number");
}
}
}
switch(Choice)
{
case 1:
Statements;
break;
case 2:
Statements;
break;
case 3:
Statements;
break;
.
.
default:
Statements;
}
class Main
{
public static void main(String args[])
{
int x=10,y;
y=x%2;
switch(y)
{
case 0:
System.out.println("Even Number");
break;
case 1:
System.out.println("Odd Number");
break;
default:
System.out.println("Invalid Choice");
}
}
}
class Main
{
public static void main(String args[])
{
int x,y;
x=Integer.parseInt(args[0]);
y=x%2;
switch(y)
{
case 0:
System.out.println("Even Number");
break;
case 1:
System.out.println("Odd Number");
break;
default:
System.out.println("Invalid Choice");
}
}
}
import java.util.*;
class Main
{
public static void main(String args[])
{
int x,y;
System.out.println("Enter x value");
Scanner s=new Scanner(System.in);
x=s.nextInt();
y=x%2;
switch(y)
{
case 0:
System.out.println("Even Number");
break;
case 1:
System.out.println("Odd Number");
break;
default:
System.out.println("Invalid Choice");
}
}
}
Check the given number is valid or invalid(value must between 20 and 30)
class Main
{
public static void main(String args[])
{
int x=24;
if(x>=20 && x<=30)
{
System.out.println("Valid Number");
}
else
{
System.out.println("Invalid Number");
}
}
}
class Main
{
public static void main(String args[])
{
int x;
x=Integer.parseInt(args[0]);
if(x>=20 && x<=30)
{
System.out.println("Valid Number");
}
else
{
System.out.println("Invalid Number");
}
}
}
import java.util.*;
class Main
{
public static void main(String args[])
{
int x;
Scanner s=new Scanner(System.in);
System.out.println("Enter x Value");
x=s.nextInt();
if(x>=20 && x<=30)
{
System.out.println("Valid Number");
}
else
{
System.out.println("Invalid Number");
}
}
}
Check the given number is valid or invalid(value must divisible by 2 and 3)
class Main
{
public static void main(String args[])
{
int x=24;
if(x%2==0 && x%3==0)
{
System.out.println("Valid Number");
}
else
{
System.out.println("Invalid Number");
}
}
}
class Main
{
public static void main(String args[])
{
int x;
x=Integer.parseInt(args[0]);
if(x%2==0 && x%3==0)
{
System.out.println("Valid Number");
}
else
{
System.out.println("Invalid Number");
}
}
}
import java.util.*;
class Main
{
public static void main(String args[])
{
int x;
Scanner s=new Scanner(System.in);
System.out.println("Enter x Value");
x=s.nextInt();
if(x%2==0 && x%3==0)
{
System.out.println("Valid Number");
}
else
{
System.out.println("Invalid Number");
}
}
}
Check the given number is valid or invalid(value must divisible by 2 and 3 not 4)
class Main
{
public static void main(String args[])
{
int x=24;
if(x%2==0 && x%3==0 && x%4 !=0)
{
System.out.println("Valid Number");
}
else
{
System.out.println("Invalid Number");
}
}
}
class Main
{
public static void main(String args[])
{
int x;
x=Integer.parseInt(args[0]);
if(x%2==0 && x%3==0 && x%4 !=0)
{
System.out.println("Valid Number");
}
else
{
System.out.println("Invalid Number");
}
}
}
import java.util.*;
class Main
{
public static void main(String args[])
{
int x;
Scanner s=new Scanner(System.in);
System.out.println("Enter x Value");
x=s.nextInt();
if(x%2==0 && x%3==0 && x%4 !=0)
{
System.out.println("Valid Number");
}
else
{
System.out.println("Invalid Number");
}
}
}
Check the given character is vowel or consonant
class Main
{
public static void main(String args[])
{
char ch='E';
if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u' || ch=='A' ||ch=='E' || ch=='I' || ch=='O' || ch=='U')
{
System.out.println("Vowel");
}
else
{
System.out.println("Consonant");
}
}
}
class Main
{
public static void main(String args[])
{
char ch;
ch=args[0].charAt(0);
if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u' || ch=='A' ||ch=='E' || ch=='I' || ch=='O' || ch=='U')
{
System.out.println("Vowel");
}
else
{
System.out.println("Consonant");
}
}
}
import java.util.*;
class Main
{
public static void main(String args[])
{
char ch;
Scanner s=new Scanner(System.in);
System.out.println("Enter Character");
ch=s.next().charAt(0);
if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u' || ch=='A' ||ch=='E' || ch=='I' || ch=='O' || ch=='U')
{
System.out.println("Vowel");
}
else
{
System.out.println("Consonant");
}
}
}
Check the given character is Small Letter or Not
class Main
{
public static void main(String args[])
{
char ch='k';
if(x>='a' && x<='z')
{
System.out.println("Small Letter");
}
else
{
System.out.println("Not a Small Letter ");
}
}
}
class Main
{
public static void main(String args[])
{
char ch;
ch=args[0].charAt(0);
if(x>='a' && x<='z')
{
System.out.println("Small Letter");
}
else
{
System.out.println("Not a Small Letter ");
}
}
}
import java.util.*;
class Main
{
public static void main(String args[])
{
char ch;
Scanner s=new Scanner(System.in);
System.out.println("Enter Character");
ch=s.next().charAt(0);
if(x>='a' && x<='z')
{
System.out.println("Small Letter");
}
else
{
System.out.println("Not a Small Letter ");
}
}
}