Computer Science, asked by orchida1, 1 month ago

Write a program that takes ages of 3 students as inputs and prints which is the greatest age.​

Answers

Answered by kamalrajatjoshi94
0

Answer:

import java.util.*;

public class Student

{

public static void main(String args[ ])

{

Scanner in=new Scanner(System.in);

int a,b,c;

System.out.println("Enter the ages of the students");

a=in.nextInt();

b=in.nextInt();

c=in.nextInt();

if(a!=b &&b!=c&&c!=a)//This condition checks whether the ages are equal or not else will print invalid input

{

if(a>b&&a>c)

{

System.out.println("The greatest age="+a);

}

else if(b>a&&b>c)

{

System.out.println("The greatest age="+b);

}

else if(c>a&&c>b)

{

System.out.println("The greatest age="+c);

}

}

else

System.out.println("Invalid input");

}

}

Similar questions