Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // CONDITIONAL IF
- import java.util.Scanner;
- public class oper_if {
- public static void main(String[] args) {
- System.out.println("Select the highest number: ");
- Double a, b, c, big;
- Scanner entry = new Scanner(System.in);
- System.out.print("1st number = ");
- a = entry.nextDouble();
- System.out.print("2nd number = ");
- b = entry.nextDouble();
- System.out.print("3rd number = ");
- c = entry.nextDouble();
- if (a > b && a > c){
- big = a;
- System.out.println("Biggest: "+big);
- } else if (b > a && b > c){
- big = b;
- System.out.println("Biggest: "+big);
- } else {
- big = c;
- System.out.println("Biggest: "+big);
- }
- // TERNARY
- final String high = a > b
- ? a + " higher than " + b
- : b + " higher than " + a;
- System.out.println(high);
- String highest = a > b && a > c
- ? a + ": highest"
- : (b > a && b > c
- ? b + ": highest" : c + ": highest");
- System.out.println(highest);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment