Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static int compareTo (String s1, String s2)
- {
- int resposta = 0;
- return compareTo (s1, s2, 0, resposta);
- }
- public static int compareTo (String s1, String s2, int i, int resposta)
- {
- if(i < s1.length())
- {
- if(s1.charAt(i) == s2.charAt(i))
- {
- resposta = 0;
- resposta = compareTo (s1, s2, i++, resposta);
- }
- else if (s1.charAt(i) > s2.charAt(i))
- {
- resposta = -1;
- }
- else
- {
- resposta = 1;
- }
- }
- return resposta;
- }
- public static int compareToIgnoreCase (String s1, String s2)
- {
- int resposta = 0;
- return compareToIgnoreCase (s1, s2, 0, resposta);
- }
- public static int compareToIgnoreCase (String s1, String s2, int i, int resposta)
- {
- if(i < s1.length())
- {
- if(s1.charAt(i) == s2.charAt(i) || s1.charAt(i) == s2.charAt(i) - 32 || s1.charAt(i) == s2.charAt(i) + 32)
- {
- resposta = 0;
- resposta = compareToIgnoreCase (s1, s2, i++, resposta);
- }
- else if (s1.charAt(i) > s2.charAt(i))
- {
- resposta = -1;
- }
- else
- {
- resposta = 1;
- }
- }
- return resposta;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement