Assignment: Module 03- Part 02
![]() |
Assignment: Module 03- Part 02 |
Write a class MaxThree to accept three numbers and find the maximum in it.
Input:
Enter the value of ‘a’ 3
Enter the value of ‘b’ 5
Enter the value of ‘c’ 1
Output:
b is maximum
Here is the Java code for class MaxThree:
import java.util.Scanner;
public class MaxThree {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the value of 'a': ");
int a = sc.nextInt();
System.out.print("Enter the value of 'b': ");
int b = sc.nextInt();
System.out.print("Enter the value of 'c': ");
int c = sc.nextInt();
int max = a;
if (b > max) {
max = b;
}
if (c > max) {
max = c;
}
System.out.println("Max is " + max);
if (max == a) {
System.out.println("a is maximum");
} else if (max == b) {
System.out.println("b is maximum");
} else {
System.out.println("c is maximum");
}
}
}