Computer Science, asked by shivi321, 1 month ago

Write a Java program to find out the greatest number from three integers A,B,C using if-else-if ladder​

Answers

Answered by anindyaadhikari13
8

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

The given problem is solved using language - Java.

import java.util.Scanner;

public class Brainly{

   public static void main(String s[]){

       Scanner sc=new Scanner(System.in);

       int a,b,c,max;

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

       if(a>b){

           if(a>c)

               max=a;

           else

               max=c;

       }

       else{

           if(b>c)

               max=b;

           else

               max=c;

       }

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

   }

}

\textsf{\large{\underline{Logic}:}}

  • Accept three numbers, say a,b and c.
  • Check if a > b and a > c. If true - print a.
  • Check if b > a and b > c. If true - print b.
  • Check if c > a and c > b. If true - print c.

\textsf{\large{\underline{Sample I/O}:}}

#1

Enter first number: 10

Enter second number: 30

Enter third number: 40

Largest number: 40

————————————————————

#2

Enter first number: 10

Enter second number: 30

Enter third number: 20

Largest number: 30

Attachments:
Similar questions