Advertisement
comsworld

Tech Fund-Methods-P09_GreaterOfTwoValues

Dec 12th, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.28 KB | None | 0 0
  1. // Judge 50/100
  2.  
  3. package TF11_methodsFunctions;
  4.  
  5. import java.util.Scanner;
  6.  
  7. public class P09_greaterOfTwoValues {
  8.     public static void main(String[] args) {
  9.         Scanner sc = new Scanner(System.in);
  10.         String inputType = sc.nextLine();
  11.         String first = sc.nextLine();
  12.         String second = sc.nextLine();
  13.  
  14.         switch (inputType){
  15.             case "int":
  16.                 int a = Integer.parseInt(first);
  17.                 int b = Integer.parseInt(second);
  18.                 System.out.println(getMax(a, b));
  19.                 break;
  20.             case "char":
  21.                 char c = first.charAt(0);
  22.                 char d = second.charAt(0);
  23.                 System.out.println(getMax(c, d));
  24.                 break;
  25.             case "String":
  26.                 System.out.println(getMax(first,second));
  27.                 break;
  28.         }
  29.     }
  30.  
  31.     private static String getMax(String a, String b) {
  32.         if (a.compareTo(b) >= 0) {
  33.             return a;
  34.         }
  35.         return b;
  36.     }
  37.  
  38.     private static char getMax(char a, char b) {
  39.         if (a > b) {
  40.             return a;
  41.         }
  42.         return b;
  43.     }
  44.  
  45.     private static int getMax(int a, int b) {
  46.         if (a > b) {
  47.             return a;
  48.         }
  49.         return b;
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement