Java - Find Largest Among three numbers.
example_1.java
/* Code From Learnoset - Learn Code Online Android App.*/
/*Download Learnoset App from PlayStore to learn coding*/
/*Example 1: Find Largest Among three numbers using if..else statement*/
public class example_1{
public static void main(String[] args) {
int n1 = 4, n2 = 3, n3 = 2;
if (n1 >= n2 && n1 >= n3)
System.out.println(n1 + " is the largest number.");
else if (n2 >= n1 && n2 >= n3)
System.out.println(n2 + " is the largest number.");
else
System.out.println(n3 + " is the largest number.");
}
}
// OUTPUT
/* 4 is the largest number .*/
example_2.java
/* Code From Learnoset - Learn Code Online Android App.*/
/*Download Learnoset App from PlayStore to learn coding*/
/*Example 2: Find the largest number among three using nested if..else statement*/
public class example_2{
public static void main(String[] args) {
double n1 = 4, n2 = 3, n3 = 5;
if (n1 >= n2) {
if (n1 >= n3)
System.out.println(n1 + " is the largest number.");
else
System.out.println(n3 + " is the largest number. (one)");
} else {
if (n2 >= n3)
System.out.println(n2 + " is the largest number.");
else
System.out.println(n3 + " is the largest number. (two)");
}
}
}
// OUTPUT
/* 5 is the largest number. (one)*/
Projects with Source Code + Video Tutorials
You can download our Java and Android Studio Projects with Source Code and Video Tutorials.
Modern Login and Register screen UI design
Programming Quiz App for Android (Offline Version)
Online Quiz Application using Firebase Realtime Database Source Code
If you have any Questions or Queries
You can mail us at info.learnoset@gmail.com
Follow us to learn Coding and get in touch with new Technologies.