In this program, we will discuss a simple concept of the program to find the largest number among three numbers in Java programming language.
In this topic, we learn how to find the biggest number from given three numbers in Java programming language. we can use the operator in Java language to find the biggest number of this program.
Among integer numbers
Program 1
import java.util.Scanner; class Large_Three{ public static void main (String args[]){ double max;//variable declaration Scanner scan=new Scanner(System.in); System.out.print("Enter the first number: "); int num1=scan.nextInt();//get input from user for first number System.out.print("Enter the second number: "); int num2=scan.nextInt();//get input from user for second number System.out.print("Enter the third number: "); int num3=scan.nextInt();//get input from user for third number if(num1>=num2 && num1>=num3){//num1 compare with num2 and num3 System.out.println("\n The largest number is: "+num1); } if(num2>=num1 && num2>=num3){//num2 compare with num1 and num3 System.out.println("\n The largest number is: "+num2); } if(num3>=num1 && num3>=num2){//num3 compare with num1 and num2 System.out.println("\n The largest number is: "+num3); } } }
When the above code is compiled and executed, it produces the following results
Enter the first number: 56 Enter the second number:89 Enter the third number: 32 The largest number : 89
Among the floating point
import java.util.Scanner; class Large_Three1{ public static void main (String args[]){ Scanner scan=new Scanner(System.in); System.out.print("Enter the first number: "); double num1=scan.nextDouble();//get input from user for first number System.out.print("Enter the second number: "); double num2=scan.nextDouble();//get input from user for second number System.out.print("Enter the third number: "); double num3=scan.nextDouble();//get input from user for third number if(num1>=num2 && num1>=num3){ System.out.println("\n The largest number is: "+num1); } if(num2>=num1 && num2>=num3){ System.out.println("\n The largest number is: "+num2); } if(num3>=num1 && num3>=num2){ System.out.println("\n The largest number is: "+num3); } } }
When the above code is compiled and executed, it produces the following results
Enter the first number: 4.6 Enter the second number:6.5 Enter the third number: 3.7 The largest number is: 6.5
import java.util.Scanner; class Large_Three1{ public static void main (String args[]){ Scanner scan=new Scanner(System.in); System.out.print("Enter the first number: "); int num1=scan.nextInt();//get input from user for first number System.out.print("Enter the second number: "); int num2=scan.nextInt();//get input from user for second number System.out.print("Enter the third number: "); int num3=scan.nextInt();//get input from user for third number if(num1>=num2 && num1>=num3){ System.out.println("\n The largest number is: "+num1); } else if(num2>=num1 && num2>=num3){ System.out.println("\n The largest number is: "+num2); } else{ System.out.println("\n The largest number is: "+num3); } } }
When the above code is compiled and executed, it produces the following results
Enter the first number: 45 Enter the second number:67 Enter the third number:80 The largest number is:80
import java.util.Scanner; class Large_Three2{ public static void main (String args[]){ Scanner scan=new Scanner(System.in); System.out.print("Enter the first number: "); int num1=scan.nextInt();//get input from user for first number System.out.print("Enter the second number: "); int num2=scan.nextInt();//get input from user for second number System.out.print("Enter the third number: "); int num3=scan.nextInt();//get input from user for third number if(num1>=num2) { if(num1>=num3){ System.out.println("\n The largest number is: "+num1); } else{ System.out.println("\n The largest number is: "+num3); } } else{ if(num2>=num3){ System.out.println("\n The largest number is: "+num2); } else{ System.out.println("\n The largest number is: "+num3); } } } }
When the above code is compiled and executed, it produces the following results
Enter the first number: 67 Enter the second number: 99 Enter the tird number: 65 The largest number is: 99
In the above, all programs, Three variables num1,num2,num3 are compared one by one using if related statements to find largest one.
Similar post
largest number of three number in C
largest number of three number in C++
largest number of three number in Python
largest number of three number in C using function
largest number of three number in C++ using function
largest number of three number in Python using function
largest number of three number in Java using method
Suggested for you
Single dimension Array in C++ language
Data type in C++ programming language
Two dimension array in C++ language
Three dimension array in C++ language
If statements in Java language
Single dimension array in Java language
Two dimension array in Java language
Three dimension array in Java language
Operator in C language with example
Single dimension array in C language
Two dimension array in C language
Three dimension array in C language
Explanation of one dimensional array In this post, we will discuss the concept of "Explanation…
Python program to calculate the sum of odd and even numbers in a list In…
Python code to Calculate sum of odd and even in a list In this tutorial,…
How to find reverse number using method In this article, we will discuss the concept…
C# inverted full pyramid star pattern In this article, we will discuss the concept of…
C# Full Pyramid star pattern program In this article, we will discuss the concept of…