Import Java.util.Scanner;
public class Demo01 {
public static void Main (string[] args) {
Scanner sc = new Scanner (system.in);
for (;;) {
String a = Sc.next ();
String B = Sc.next ();
int num = A.compareto (b);
SYSTEM.OUT.PRINTLN (num);
}
}
}
1. When two comparison strings are in English and vary in length,
1) As long as the length of a character, the returned result is a two-length subtraction value
A= "Hello";
B= "Hell";
Num=1;
Or
A= "H";
b= "Hello";
num=4;
2) The length is different and the first few characters are different, starting from the first bit, when a different character is found, the value returned is the value of the comparison between the two characters
A= "ASSDF";
b= "BDD";
Num=-1;
2. When the two comparison strings are in English and are of equal length,
1) A single character
A= "a"; 97
B= "B"; 98
Num=-1;
2) Multiple characters, the first character is different, the first character is directly compared
A= "Ah"; a=97
b= "EG"; E=101
num=-4;
3) Multiple characters, the first character is the same, the second character is directly compared, and so on
A= "AE"; E=101
b= "AA"; a=97
num=4;
Comparison of Java strings CompareTo