Write a class MaxThree to accept three numbers and find the maximum in it.

0

Assignment: Module 03- Part 02

Write a class MaxThree to accept three numbers and find the maximum in it.
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");
    }
  }
}   

👉Write a class LoopExample2 to display the output as below using control structures👈

Post a Comment

0Comments
Post a Comment (0)

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Accept !
✨ Updates