Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class CompareMethod {
- public static void main(String[] args){
- String a = "a";
- String b = "b";
- String A = "A";
- String B = "B";
- String ab = "ab";
- String aa = "aa";
- String cat = "cat";
- String can = "can";
- String dog = "dog";
- int compareab;
- int compareAB;
- int compareabaa;
- int comparecatcan;
- int comparecatdog;
- int compareAa;
- /* Give "a" a value of zero as a start of the alphabet and "z" a value of 25 to end the alphabet.
- *
- * Capital letters are applied in the same way. To determine a single letter's value comparable to that of another,
- * including same case, just subtract that value of the last letter compared to that of the first letter in the compareTo lines.
- *
- * The letters that are compared are the first letters that are found different in the string.
- *
- * When comparing letters of a different case, there is a 32 magnitude difference in either way, depending on what is being subtracted
- *
- * In conclusion, all letters and their cases are given a numerical value to be "compared" when using the compareTo method
- *
- * Sorry for the scrappy code, I was using it to move stuff around and compare the compareTo method to other things :)
- */
- System.out.println("Comparing String: " + a + " String: " + b);
- compareab = "a".compareTo("b");
- System.out.println(compareab); //Should output 1 "a - b"
- System.out.println("Comparing String: " + A + " String: " + B);
- compareAB = "A".compareTo("B");
- System.out.println(compareAB); //Should also output 1 "A - B"
- System.out.println("Comparing String: " + ab + " String: " + aa);
- compareabaa = "ab".compareTo("aa");
- System.out.println(compareabaa); //Should output -1 "ab - aa";
- System.out.println("Comparing String: " + cat + " String: " + can);
- comparecatcan = "cat".compareTo("can");
- System.out.println(comparecatcan); //Should output 6 "cat - can"
- System.out.println("Comparing String: " + cat + " String: " + dog);
- comparecatdog = "cat".compareTo("dog");
- System.out.println(comparecatdog); //Should output -1 "cat - dog"
- System.out.println("Comparing String: " + A + " String: " + a);
- compareAa = "A".compareTo("a"); //Should output -25 "A - a"
- System.out.println(compareAa);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment