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

Comments

Popular posts from this blog

Program to define a class 'employee' with data members as empid, name and salary. Accept data for 5 objects using Array of objects and print it.

Program to input age from user and throw user-defined exception if entered age is negative

Define a class Student with four data members such as name, roll no.,sub1, and sub2. Define appropriate methods to initialize and display the values of data members. Also calculate total marks and percentage scored by student.