- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 find maximum of three numbers
The maximum among three numbers can be found using an if else statement. A program that demonstrates this is given as follows.
Example
public class Example { public static void main(String args[]) { int num1 = 15; int num2 = -5; int num3 = 7; if (num1 >= num2 && num1 >= num3) System.out.println( num1 + " is the maximum number."); else if (num2 >= num1 && num2 >= num3) System.out.println( num2 + " is the maximum number."); else System.out.println( num3 + " is the maximum number."); } }
Output
15 is the maximum number.
Now let us understand the above program.
First, the three numbers are defined. If num1 is greater than num2 and num3, then it is the maximum number. If num2 is greater than num1 and num3, it is the maximum number. Otherwise, num3 is the maximum number. The code snippet that demonstrates this is given as follows.
int num1 = 15; int num2 = -5; int num3 = 7; if (num1 >= num2 && num1 >= num3) System.out.println( num1 + " is the maximum number."); else if (num2 >= num1 && num2 >= num3) System.out.println( num2 + " is the maximum number."); else System.out.println( num3 + " is the maximum number.");
- Related Articles
- Python program to find the maximum of three numbers
- C# program to find the maximum of three numbers
- Java Program to Find the Largest Among Three Numbers
- Java program to find smallest of the three numbers using ternary operators
- Java program to find largest of the three numbers using ternary operators
- Program to find largest of three numbers - JavaScript
- Java Program to get the maximum of three long values
- Java program to Largest number among three numbers
- Python program maximum of three.
- Maximum Product of Three Numbers in C++
- 8085 program to find maximum and minimum of 10 numbers
- 8085 program to find maximum of two 8 bit numbers
- Program to find maximum sum of multiplied numbers in Python
- Program to find the common ratio of three numbers in C++
- C++ Program to Find Largest Number Among Three Numbers

Advertisements