Advertisement
mirozspace

GTV

Feb 11th, 2019
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4.  
  5. public class Pr9GreateOfTwoValues {
  6. public static void main(String[] args) throws IOException {
  7. BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  8. String type = reader.readLine();
  9. String str1 = reader.readLine();
  10. String str2 = reader.readLine();
  11. reader.close();
  12. getMax(type, str1, str2);
  13. }
  14.  
  15. private static void getMax(String type, String str1, String str2) {
  16. if ("int".equals(type)) {
  17. int num1 = Integer.parseInt(str1);
  18. int num2 = Integer.parseInt(str2);
  19. if (num1 > num2) {
  20. System.out.println(num1);
  21. } else {
  22. System.out.println(num2);
  23. }
  24. } else if ("char".equals(type)) {
  25. char ch1 = str1.charAt(0);
  26. char ch2 = str2.charAt(0);
  27. if (ch1 > ch2) {
  28. System.out.println(ch1);
  29. } else {
  30. System.out.println(ch2);
  31. }
  32. } else if ("string".equals(type)) {
  33. int result = str1.compareTo(str2);
  34. if (result == 0)
  35. System.out.println("str1 and str2 are equal");
  36. else if (result < 0)
  37. System.out.println(str2);
  38. else
  39. System.out.println(str1);
  40. }
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement