comparestring.java
来自「java2应用开发指南第一版」· Java 代码 · 共 20 行
JAVA
20 行
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 + =
减小字号Ctrl + -
显示快捷键?