Page 181 - Computer science 868 Class 12
P. 181
if(condition 2)
{
Statement 2;
}
if(condition 3)
{
Statement 3;
}
For example:
Input marks in Physics, Chemistry and Maths. Print the highest marks and the name of the subject.
class greatest_marks
{
public static void main(int pm, int cm, int mm)
{
if(pm>cm && pm>mm)
{
System.out.println("The highest marks in Physics, i.e.," + pm);
}
if(cm>pm && cm>mm)
{
System.out.println("The highest marks in Chemistry, i.e.," +cm);
}
if(mm>pm && mm>cm)
{
System.out.println("The highest marks in Maths, i.e.," + mm);
}
}
}
Input:
Physics = 90
Chemistry = 99
Maths = 98
Output:
The highest marks in Chemistry, i.e., 99
Let us take some more examples:
int num = sc.nextInt();
if(num>10)
System.out.println(num+ "greater than 40");
if(num%10==0)
System.out.println("Last digit is 0");
if(num%2==0)
System.out.println("It is an even number");
if(num%9==0)
System.out.println("It is a multiple of nine");
This code finds whether the number taken is greater than 40, its last digit is 0, an even number or a multiple of nine.
179
Statements and Scope 179

