Math, asked by Anonymous, 1 month ago

write a java program to determine the largest of two numbers ?

expecting great answers from computer masters !
(copythat, brainlyprogrammer) !!

Answers

Answered by CopyThat
21

Program : [JAVA]

import java.util.Scanner;

public class FindLarger

{

public static void main(String args [ ] )

{

Scanner input = new Scanner(System.in);

System.out.println(''Enter the first number: '');

int num1 = input.nextInt();

System.out.println(''Enter the second number: '')

int num2 = input.nextInt();

int largest = GetLargest(num1, num2);

System.out.println(''Largest of '' + num1 + '' and '' + num2 + '' is '' + largest);

input.close();

}

static int GetLargest(int a, int b)

{

if (a > b)

return a;

return b;

}

}

Output :

Enter the first number: 17

Enter the second number:8

Largest of 17 and 8 is 17

Answered by anindyaadhikari13
24

Solution:

The given problem is solved using - Java.

import java.util.*;

public class Max{

   public static void main(String s[]){

       Scanner _=new Scanner(System.in);

       int a,b;

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

       a=_.nextInt();

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

       b=_.nextInt();

       _.close();

       System.out.printf("Largest among %d and %d is %d.",a,b,Math.max(a,b));

   }

}

The problem is solved using Math class. Math.max() returns highest of two numbers. Here, we have taken two numbers as input and then calculated the largest number using this function.

See attachment for output.

Attachments:
Similar questions