Advertisement
damesova

Greater Of Two Values

Feb 18th, 2019
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.09 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class _09_GreaterOfTwoValues {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         String type = scanner.nextLine();
  7.  
  8.         if (type.equals("int")) {
  9.             int firstVar = Integer.parseInt(scanner.nextLine());
  10.             int secondVar = Integer.parseInt(scanner.nextLine());
  11.             System.out.println(getMax(firstVar, secondVar));
  12.         } else {
  13.             String firstVar = scanner.nextLine();
  14.             String secondVar = scanner.nextLine();
  15.             System.out.println(getMax(firstVar, secondVar));
  16.         }
  17.     }
  18.  
  19.     static int getMax(int first, int second){
  20.         if (first >= second) {
  21.             return first;
  22.         }
  23.         return second;
  24.     }
  25.  
  26.     static char getMax(char first, char second) {
  27.         if (first >= second){
  28.             return first;
  29.         }
  30.         return second;
  31.     }
  32.  
  33.     static String getMax(String first, String second){
  34.         if (first.compareTo(second) >= 0) {
  35.             return first;
  36.         }
  37.         return second;
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement