Advertisement
Guest User

greaterOfTwoValues

a guest
Oct 23rd, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.40 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class greaterOfTwoValues {
  4.     public static void main(String[] args) {
  5.  
  6.         Scanner console = new Scanner(System.in);
  7.  
  8.         String type = console.nextLine().toLowerCase();
  9.         String firstInput = console.nextLine();
  10.         String secondInput = console.nextLine();
  11.  
  12.         if (type.equals("int")) {
  13.             int first = Integer.parseInt(firstInput);
  14.             int second = Integer.parseInt(secondInput);
  15.             System.out.println(getMax(first, second));
  16.         } else if (type.equals("char")) {
  17.             char firstChar = firstInput.charAt(0);
  18.             char secondChar = secondInput.charAt(0);
  19.             System.out.println((char) getMax(firstChar, secondChar));
  20.         } else if (type.equals("String")) {
  21.             System.out.println(getMax(firstInput, secondInput));
  22.         }
  23.  
  24.  
  25.     }
  26.  
  27.     private static int getMax(int first, int second) {
  28.         if (first >= second) {
  29.             return first;
  30.         }
  31.         return second;
  32.     }
  33.  
  34. //    static char getMax(char firstChar, char secondChar) {
  35. //        if (firstChar >= secondChar) {
  36. //            return firstChar;
  37. //        }
  38. //        return secondChar;
  39. //    }
  40.  
  41.     static String getMax(String firstInput, String secondInput) {
  42.         if (firstInput.compareTo(secondInput) >= 0) {
  43.             return firstInput;
  44.         }
  45.         return secondInput;
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement