OpKaTa

9ta zadacha Method Exercise

Feb 24th, 2020
428
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class GreaterofTwoValues {
  4. public static void main(String[] args) {
  5. Scanner scan = new Scanner(System.in);
  6.  
  7. String command = scan.nextLine();
  8.  
  9. switch (command) {
  10. case "int":
  11. int num = Integer.parseInt(scan.nextLine());
  12. int num2 = Integer.parseInt(scan.nextLine());
  13. int result = getMaxInteger(num, num2);
  14. System.out.println(result);
  15. break;
  16. case "char":
  17. char a = scan.nextLine().charAt(0);
  18. char b = scan.nextLine().charAt(0);
  19. getCharMax(a, b);
  20.  
  21. break;
  22. case "String":
  23. String input = scan.nextLine();
  24. String input2 = scan.nextLine();
  25. String resultString = getStringMax(input, input2);
  26. System.out.println(resultString);
  27. break;
  28. }
  29. }
  30.  
  31. static String getStringMax(String input, String input2) {
  32.  
  33. if (input.compareTo(input2)>=0) {
  34. return input;
  35. }else {
  36. return input2;
  37. }
  38. }
  39.  
  40. static void getCharMax (char a, char b) {
  41.  
  42. if (a>b) {
  43. System.out.println(a);
  44. return;
  45. }
  46. System.out.println(b);
  47. }
  48.  
  49.  
  50. static int getMaxInteger(int num, int num2) {
  51.  
  52. if (num > num2) {
  53. return num;
  54. }
  55. return num2;
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment