IF Condition

It is a conditional statement. all the statements will execute based on the condition else it will check the next condition.
Syntax:
            if (Condition1)
{
            Statements;
}
else if( Condition2)
{
            Statements;
}

else

------
- - - - - -

TO FIND THE BIG NUMBER OUT OF TWO NUMBERS.

import java.util.Scanner;
class Big
{
public static void main(String args[])
{
int a,b;
Scanner read=new Scanner(System.in);
System.out.println(“Enter 2 nos”);
a=read.nextInt();
b=read.nextInt();
if(a>b)
{
System.out.println("A is big"+a);
}
else
{
System.out.println("B is big"+a);
}
}
}

PROGRAM TO FIND THE BIG NUMBER OUT OF FOUR NUMBERS.

import java.util.Scanner;
class Four
{
public static void main(String args[])
{     
int a,b,c,d;
Scanner read=new Scanner(System.in);
System.out.println(“Enter 3 nos”);
a=read.nextInt();
b=read.nextInt();
c=read.nextInt();
d=read.nextInt();
if(a>b&&a>c&&a>d)
{
System.out.println("A is big");
}
else
if(b>c&&b>d)
{
System.out.println("B is big");
}
else
if(c>d)
{
System.out.println("C is big");
}
else
{
System.out.println("D is big");
}
}
}

WRITE A PROGRAM TO FIND THE GRADE OF A STUDENT.

import java.util.Scanner;
class Grade
{
public static void main(String args[])
{
int a,b,c,d,e;
Scanner read=new Scanner(System.in);
System.out.println(“Enter 5 subjects marks”);
a=read.nextInt();
b=read.nextInt();
c=read.nextInt();
d=read.nextInt();
e=read.nextInt();
int tot=a+b+c+d+e;
int avg=tot/6;
if(a<35||b<35||c<35||d<35||e<35)
{
System.out.println("Fail");
}
else if(avg>35&&avg<45)
{
System.out.println("Third Class");
}
else
if(avg>45&&avg<60)
{
System.out.println("Second Class");
}
else
{
System.out.println("First Class");
}
}
}

 

For
Online Classes

Contact Us: 9885348743