本人刚开始学,很多都还没理解能请人帮忙讲解下吗?谢谢啊
1. Suppose s1 and s2 are two strings. Which of the following statements or expressions is incorrect?a) boolean b = s1.equals(s2);
b) boolean b = (s1 == s2);
c) boolean b = (s1 >= s2);
d) int b = s1.compareTo(s2);
e) boolean b = ((s1.length() – s2.length()) > 0 );2. Consider the following java code?
String s1 = “one”;
String s2 = new String(“one”);
    String s3 = s1;Which of the following statement is true?
a) boolean b = (s1==s2);
b) boolean b = (s2==s3);
c) boolean b = (s2.equals(s3));
d) boolean b = (s1 == NULL);
e) boolean b = (s3.equals(“”)); 

解决方案 »

  1.   

    第一个是C 和  E错了吧
    false
    false
    true
      

  2.   

    你去总结下==和equals的区别吧。自己总结出来更好。
      

  3.   

    1   c,e
    分析:字符串是没有>=这种表达式比较的,所以pass掉,e的话取长度是没错的,但是这里的长度要拿出来之后才能操作,不能直接操作的!  或者是在前面加个(int)转换下!
    2  第三个是正确的,其它的都是false。  这里说下==和equals的区别,==是地址,equals是值比较。
      

  4.   

    ==和equals不是一句话就说完的。
      

  5.   

    就是考equals和==区别的,楼主百度一下,就有了,基础啊
      

  6.   

    java中的String类型比较不可以用==吧?