Syntax error Java program to Largest number among three numbers

Java program to Largest number among three numbers



Comparing three integer variables is one of the simplest programs you can write at ease.

  •  Take two integer variables, say A, B& C
  •  Assign values to variables
  •  If A is greater than B & C, Display A is the largest value
  •  If B is greater than A & C, Display B is the largest value
  •  If C is greater than A & B, Display A is the largest value
  •  Otherwise, Display A, B & C are not unique values

Example

import java.util.Scanner;
public class LargestOfThreeNumbers {
   public static void main(String args[]){
      Scanner sc =new Scanner(System.in);
      System.out.println("Enter 1st number :");
      int a = sc.nextInt();
      System.out.println("Enter 2nd number :");
      int b = sc.nextInt();
      System.out.println("Enter 3rd number :");
      int c = sc.nextInt();

      if ( a > b && a > c ){
         System.out.println("Largest number is ::"+ a);
      }else if ( b > a && b > c ){
         System.out.println("Largest number is ::"+ b);
      }else if ( c > a && c > b ){
         System.out.println("Largest number is ::"+ c);
      }else{
         System.out.println("Cnnot validate");
      }
   }
}

Output

Enter 1st number :
2
Enter 2nd number :
66
Enter 3rd number :
8
Largest number is ::66
Updated on: 2020-03-13T09:53:45+05:30

4K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements