SHARE
TWEET

Untitled

MladenPetrov Oct 10th, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. public class GreaterOfTwoValues {
  4.  
  5.     public static int getMax (int firstNum, int secondNum) {
  6.         if (firstNum > secondNum){
  7.             return firstNum;
  8.         }
  9.         return secondNum;
  10.     }
  11.  
  12.     public static char getMax(char first, char second) {
  13.         if (first > second) {
  14.             return first;
  15.         }
  16.         return second;
  17.     }
  18.  
  19.     public static String getMax(String first, String second) {
  20.         if (first.compareTo(second) >= 0) {
  21.             return first;
  22.         }
  23.         return second;
  24.     }
  25.  
  26.     public static void main(String[] args) {
  27.         Scanner scanner = new Scanner(System.in);
  28.  
  29.         String input = scanner.nextLine();
  30.  
  31.         if (input.equals("int")) {
  32.             int firstNum = scanner.nextInt();
  33.             int secondNum = scanner.nextInt();
  34.             int max = getMax(firstNum, secondNum);
  35.             System.out.println(max);
  36.         }
  37.  
  38.         if (input.equals("char")) {
  39.             char first = scanner.nextLine().charAt(0);
  40.             char second = scanner.nextLine().charAt(0);
  41.             char max = getMax(first, second);
  42.             System.out.println(max);
  43.         }
  44.  
  45.         if (input.equals("string")) {
  46.             String first = scanner.nextLine();
  47.             String second = scanner.nextLine();
  48.             String max = getMax(first, second);
  49.             System.out.println(max);
  50.         }
  51.  
  52.     }
  53. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top