rangga_hrdme

CONDITIONAL: IF

Apr 19th, 2021
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.28 KB | None | 0 0
  1. // CONDITIONAL IF
  2. import java.util.Scanner;
  3.  
  4. public class oper_if {
  5.        
  6.     public static void main(String[] args) {
  7.         System.out.println("Select the highest number: ");
  8.        
  9.         Double a, b, c, big;
  10.        
  11.         Scanner entry = new Scanner(System.in);
  12.         System.out.print("1st number = ");
  13.         a = entry.nextDouble();
  14.        
  15.         System.out.print("2nd number = ");
  16.         b = entry.nextDouble();
  17.        
  18.         System.out.print("3rd number = ");
  19.         c = entry.nextDouble();
  20.        
  21.         if (a > b && a > c){
  22.             big = a;
  23.             System.out.println("Biggest: "+big);
  24.         } else if (b > a && b > c){
  25.             big = b;
  26.             System.out.println("Biggest: "+big);
  27.         } else {
  28.             big = c;
  29.             System.out.println("Biggest: "+big);
  30.         }        
  31.        
  32.        
  33.         // TERNARY
  34.         final String high = a > b
  35.                 ? a + " higher than " + b
  36.                 : b + " higher than " + a;
  37.         System.out.println(high);
  38.        
  39.         String highest = a > b && a > c
  40.                 ? a + ": highest"
  41.                 : (b > a && b > c
  42.                     ? b + ": highest" : c + ": highest");
  43.         System.out.println(highest);
  44.     }          
  45. }
  46.  
Advertisement
Add Comment
Please, Sign In to add comment