Computer Science, asked by Anonymous, 3 months ago

Write a program in Java to accept three numbers and print the largest number.​

Answers

Answered by anindyaadhikari13
2

Required Answer:-

Question:

  • Write a program in Java to accept three numbers and print the largest number.

Solution:

Here is the program.

import java.util.*;

public class Max {

 public static void main(String[] args) {

   int a, b, c, max;

   Scanner sc=new Scanner(System.in);

   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();

   max=Math.max(a, Math.max(b, c));

   System.out.println("\nLargest Number is: "+max);

   sc.close();

 }

}

Explanation:

  • The Math.max() function is used to find out largest among two numbers.
  • Math.max(b, c)) will find out the largest among b and c. Then it will compare with a. It will check if a is greater than largest among b and c or not.
  • Result obtained will be the largest number.

Refer to the attachment .

Attachments:
Answered by elenasen
3

Explanation:

please flw me my friend and I hope it helps you

Attachments:
Similar questions