Advertisement
Guest User

Untitled

a guest
Feb 27th, 2015
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. public static int compareTo (String s1, String s2)
  2. {
  3. int resposta = 0;
  4. return compareTo (s1, s2, 0, resposta);
  5. }
  6.  
  7. public static int compareTo (String s1, String s2, int i, int resposta)
  8. {
  9. if(i < s1.length())
  10. {
  11. if(s1.charAt(i) == s2.charAt(i))
  12. {
  13. resposta = 0;
  14. resposta = compareTo (s1, s2, i++, resposta);
  15. }
  16.  
  17. else if (s1.charAt(i) > s2.charAt(i))
  18. {
  19. resposta = -1;
  20. }
  21.  
  22. else
  23. {
  24. resposta = 1;
  25. }
  26.  
  27. }
  28.  
  29. return resposta;
  30. }
  31.  
  32.  
  33.  
  34. public static int compareToIgnoreCase (String s1, String s2)
  35. {
  36. int resposta = 0;
  37. return compareToIgnoreCase (s1, s2, 0, resposta);
  38. }
  39.  
  40. public static int compareToIgnoreCase (String s1, String s2, int i, int resposta)
  41. {
  42. if(i < s1.length())
  43. {
  44. if(s1.charAt(i) == s2.charAt(i) || s1.charAt(i) == s2.charAt(i) - 32 || s1.charAt(i) == s2.charAt(i) + 32)
  45. {
  46. resposta = 0;
  47. resposta = compareToIgnoreCase (s1, s2, i++, resposta);
  48. }
  49.  
  50. else if (s1.charAt(i) > s2.charAt(i))
  51. {
  52. resposta = -1;
  53. }
  54.  
  55. else
  56. {
  57. resposta = 1;
  58. }
  59.  
  60. }
  61.  
  62. return resposta;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement