AIM: – Write a program to find maximum of three numbers.

Here we are writing about Write a program to find the maximum of three numbers in Java. Our initiative is that the user understands code by reading comments so that he/she can become capable to any understand code in this programming world.

Source Code: –

```import java.util.Scanner;

public class MaxOfThreeNumbers {

public static void main(String[] args) {

int firstNumber,secondNumber,thirdNumber, maxNumber;
Scanner scanner = new Scanner(System.in);

//Reading three numbers from the console
System.out.print("Enter the three numbers:- ");
firstNumber = scanner.nextInt();
secondNumber = scanner.nextInt();
thirdNumber = scanner.nextInt();

* If first number is greater than second number then it is checked if it is greater than third.
* If yes then first number is maximum, otherwise third number is maximum.
* If first number is not greater than second number then it is checked if second number is
* greater than third number. If yes then second number is maximum, otherwise third
* number is maximum.
*/
if(firstNumber > secondNumber) {
if(firstNumber > thirdNumber) {
maxNumber = firstNumber;
} else {
maxNumber = thirdNumber;
}
} else {
if(secondNumber > thirdNumber) {
maxNumber = secondNumber;
} else {
maxNumber = thirdNumber;
}
}
System.out.println("Maximum of three numbers is " + maxNumber);
}
}```

Output:

0
Categories: Uncategorized

#### Vishal Sharma

Currently pursuing Computer Science degree from G.B Pant Government Engineering college, New Delhi.