# Ternary Operator in Java

Hi Programmers, Welcome to New post Ozanecare. This post i will write the program to find highest of numbers using ternary operator. To calculated lowest of any numbers, we should give less (<) symbol in place of higher(>) symbol.
The Ternary Operator is used to replace nested if statements with shorter and very readable codes. The Ternary operator is decision making operators is used to compare two values.the ternary operator has the combination greater (>)
Question (?) and colon (:) operators.Let’s see the programs.

1.Ternary operator to check highest of two numbers.

2.Ternary operator removes nested if statement.

3.Find Highest of three numbers using ternary operator.

4.Highest of Four numbers using ternary operator.

The all combined codes.

```//Highest of Two Numbers
package JavaPackage;
import java.util.*;

public class First
{
public static void main(String[] args)
{
Scanner sc =new Scanner (System.in);
int a, b, c;
System.out.println("Enter First Number : ");
a = sc.nextInt();
System.out.println("Enter Second Number : ");
b = sc.nextInt();

c = a > b ? a : b; System.out.println("Highest of Two Numbers : " + c);
}
}

// Highest of Three Numbers
package JavaPackage;
import java.util.*;

public class First
{
public static void main(String[] args)
{
Scanner sc =new Scanner (System.in);

int a, b, c;
System.out.println("Enter Three Numbers : ");
a = sc.nextInt();
b = sc.nextInt();
c = sc.nextInt();

int large = a > b ? (a > c ? a : c) : (b > c ? b : c);
System.out.println("Highest of Three Numbers : " + large);
}
}
//Highest of Four Numbers
package JavaPackage;
import java.util.*;
public class Test
{
public static void main(String[] args)
{
Scanner sc =new Scanner (System.in);
int a, b, c,d;
System.out.println("Enter Four Numbers : ");
a = sc.nextInt();
b = sc.nextInt();
c = sc.nextInt();
d = sc.nextInt();

int t1, t2, lar;
t1 = (a > b ? a : b);
t2 = (c > d ? c : d);
lar = (t1 > t2 ? t1 : t2);
System.out.println("Highest of Four Number : " + lar);
}
}```

Happy coding…Thanks.