Computer Science, asked by Atlas99, 2 months ago

Java programming

Write a program to accept three numbers as parameter and find the highest.​

Answers

Answered by anindyaadhikari13
8

\textsf{\large{\underline{Solution}:}}

The given problem is solved using language - Java.

public class Brainly{

   public static void main(int a,int b,int c){

       System.out.println("Entered numbers: "+a+", "+b+" and "+c+".");

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

       System.out.println("Largest Number: "+max);

   }

}

\textsf{\large{\underline{Explanation}:}}

  • Math.max() function returns the highest value among two numbers.
  • To calculate the largest among three numbers, we have first calculated the maximum of last two numbers and then compared that number with the first number entered to get the highest number.

See the attachment for output.

Attachments:

anindyaadhikari13: Thanks for the brainliest :)
Answered by kamalrajatjoshi94
2

Answer:

Program:-

import java.util.*;

public class Main

{

void Greatest(int a,int b,int c)

{

if(a>b&&a>c)

System.out.println("Greatest number:"+a);

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

System.out.println("Greatest number:"+b);

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

System.out.println("Greatest number:"+c);

else

System.out.println("All the numbers are equal");

}

public static void main(String args[])

{

Scanner in=new Scanner(System.in);

Main ob=new Main();

int n,n1,n2;

System.out.println("Enter the numbers");

n=in.nextInt();

n1=in.nextInt();

n2=in.nextInt();

ob.Greatest(n,n1,n2);

}

}

Logic:-

  • Declare it under a method so the parameter list is more better and the processing time is reduced.
  • Now place the condition in case a is greater than both the numbers then it displays a otherwise b else c and if no number greater it displays all the numbers are equal
  • Now declare the main method create the scanner object and create the object now input 3 numbers and place the inputted numbers during the call of the object.
Attachments:
Similar questions