Computer Science, asked by spiritgaming38, 1 month ago

Write a program in Java to accept any three numbers and find the
greatest of these numbers.​

Answers

Answered by anindyaadhikari13
0

Answer:

This is the required Java program for the question.

import java.util.*;

public class Max    {

   public static void main(String args[])  {

       Scanner sc=new Scanner(System.in);

       int a,b,c;

       System.out.print("Enter first number:   ");

       a=sc.nextInt();

       System.out.print("Enter second number:   ");

       b=sc.nextInt();

       System.out.print("Enter third number:   ");

       c=sc.nextInt();

       sc.close();

       System.out.println("The largest number is:  "+Math.max(a,Math.max(b,c)));

   }

}

Logic:

  1. Enter three numbers, say a,b and c.
  2. Find the maximum of b and c using Math.max() function.
  3. After finding out the maximum value of b and c, compare that value with a and find the maximum again using Math.max() function.
  4. Display the greatest value.

Refer to the attachment.

•••♪

Attachments:
Similar questions