Advertisement
Guest User

Untitled

a guest
Jan 19th, 2020
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3.  
  4. public class Demo {
  5.  
  6. static int getMax(int number1, int number2){
  7. return Math.max(number1, number2);
  8. }
  9. static char getMax(char symbol1,char symbol2){
  10. if ((int) symbol1 > (int) symbol2) {
  11. return symbol1;
  12. }
  13. return symbol2;
  14. }
  15. static String getMax(String word1,String word2){
  16. int word3 = word1.length();
  17. int word4 = word2.length();
  18. if(word3 > word4){
  19. return word1;
  20. }
  21. return word2;
  22. }
  23.  
  24.  
  25. public static void main(String[] args) {
  26. Scanner scanner = new Scanner(System.in);
  27. String word = scanner.nextLine();
  28.  
  29. switch(word){
  30. case "int":
  31. int number1 = Integer.parseInt(scanner.nextLine());
  32. int number2 = Integer.parseInt(scanner.nextLine());
  33. System.out.println(getMax(number1,number2));
  34. break;
  35. case "char":
  36. char symbol1 = scanner.nextLine().charAt(0);
  37. char symbol2 = scanner.nextLine().charAt(0);
  38. System.out.println(getMax(symbol1,symbol2));
  39. break;
  40. case "String":
  41. String word1 = scanner.nextLine();
  42. String word2 = scanner.nextLine();
  43. System.out.println(getMax(word1,word2));
  44. break;
  45. }
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement