Advertisement
Guest User

Greater_Of_Two_Values

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