Tuesday, 22 November 2016

Largest among three numbers

This is a Java Program to find largest between three numbers using Nested If Else statement. We have taken three integer numbers from which we will find the largest integer. Here is the source code of the Java Program. You can write the same program using ternary operator.


PROGRAM
public class LargestAmongThree {

 public static void main(String[] args) {
  int x = 10, y = 15, z = 12;
  System.out.print("Laregest number among three is : ");
  if(x > y) {
   if(x > z) {
    System.out.print(x);
   }
   else {
    System.out.print(z);
   }
  }
  else {
   if(y > z) {
    System.out.print(y);
   }
   else
   {
    System.out.print(z);
   }
  }
 }
}
OUTPUT
C:\>javac LargestAmongThree.java
C:\>java LargestAmongThree
Largest number among three is : 15

No comments:

Post a Comment