📄 comparestring.java
字号:
class CompareString
{
public static void main(String[] args)
{
String str = "this is a test";
//不相同,r1为负值
int r1 = str.compareTo("this is a test and more");
//不相同,r2为负值,原因是'n'<'a'
int r2 = str.compareTo("this is not a test");
//相同,r3为零
int r3 = str.compareTo("this is a test");
//不相同,r4为正值,原因是't' > 'n'
int r4 = str.compareTo("no, this is not a test");
//不相同,r5为正值,原因是str长度小
int r5 = str.compareTo("this");
//类型转换错误
//int r6 = str.compareTo(new Integer(10));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -