Advertisement
Guest User

GreaterNumber

a guest
Feb 20th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. /**
  4. * Created by zdravko on 19.02.19.
  5. */
  6. public class GreaterOfTwo {
  7. public static void main(String[] args) {
  8. Scanner console = new Scanner(System.in);
  9.  
  10. String type = console.nextLine();
  11.  
  12. if ("int".equals(type)){
  13. int first = Integer.parseInt(console.nextLine());
  14. int second = Integer.parseInt(console.nextLine());
  15.  
  16. // first = Math.abs(first);
  17. // second = Math.abs(second);
  18.  
  19.  
  20. System.out.println(getGreater(first,second));
  21.  
  22. } else if ("char".equals(type)){
  23. String str1 = console.nextLine();
  24. String str2 = console.nextLine();
  25. char ch1 = str1.charAt(0);
  26. char ch2 = str2.charAt(0);
  27.  
  28.  
  29. System.out.println(getGreater(ch1,ch2));
  30.  
  31. } else if ("String".equals(type)){
  32. String word1 = console.nextLine();
  33. String word2 = console.nextLine();
  34.  
  35. System.out.println(getGreater(word1,word2));
  36. }
  37. }
  38.  
  39. static int getGreater(int n1,int n2){
  40. if (n1 >= n2){
  41. return n1;
  42. } else {
  43. return n2;
  44. }
  45. }
  46.  
  47. static char getGreater(char ch1,char ch2){
  48. if (ch1 >= ch2){
  49. return ch1;
  50. } else {
  51. return ch2;
  52. }
  53. }
  54.  
  55. static String getGreater(String word1,String word2){
  56. if (word1.compareTo(word2) >= 0){
  57. return word1;
  58. } else {
  59. return word2;
  60. }
  61. }
  62.  
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement