Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
Advertisements