Math, asked by vishal41943, 1 year ago

Write a java program to find the largest among two numbers

Answers

Answered by DAV45
6
Find Largest of Two Numbers

To find the largest number of/in two numbers in Java Programming, you have to ask to the user to enter the two number to start checking which one is larger to display the largest number on the screen as shown in the following program.

Java Programming Code to Find Largest of Two Numbers

Following Java Program ask the user to enter the two numbers, to find the greatest/largest between the two numbers, then display the result on the screen:

/* Java Program Example - Find Largest of Two Numbers */ import java.util.Scanner; public class JavaProgram { public static void main(String args[]) { int a, b, big; Scanner scan = new Scanner(System.in); System.out.print("Enter Two Number : "); a = scan.nextInt(); b = scan.nextInt(); if(a>b) { big = a; } else { big = b; } System.out.print("Largest of Two Number is " +big); }

Answered by mithulpranav24826
4

Answer:

import java.io.*;

public class big2  

{

   public static void main(String[] args) throws IOException

   {

       InputStreamReader isr=new InputStreamReader(System.in);

       BufferedReader abc= new BufferedReader(isr);

       System.out.println("Enter the First Number");

       int a=Integer.parseInt(abc.readLine());

       System.out.println("Enter the Second Number");

       int b=Integer.parseInt(abc.readLine());

       if(a>b)

       {

           System.out.println("First number is the greatest");

       }

       else if (b>a)

           System.out.println("Second number is the greatest");

     

       

   }

}

Answerd by M.Mithul Pranav

Hope it helps

Similar questions