下列代码片段执行结果是:String s=new String(”abc”); String s1=new String(s); if(s==s1){ System.out.println(”Hello”); } if(s.equals(s1)){ System.out.println(”World”); }
A: Hello World
B: Hello
C: World
D: Null
A: Hello World
B: Hello
C: World
D: Null
举一反三
- 请说出下列代码的执行结果 : String s = "abcd"; String s1 = new String(s); if (s = = s1) System.out.println("the same"); if (s.equals(s1)) System.out.println("equals");
- 以下要输出“hello,world!”正确的是? A: String s=String.format("%1s%2s","hello","world");System.out.println(s); B: String s=String.format("%1$s,%2$s","hello","world");System.out.println(s); C: String s=String.format("%s,%s","hello","world");System.out.println(s); D: String s=String.format("%1s,%2s","hello","world");System.out.println(s);
- import java.io.*;public class abc{public static void main(String args[ ]){ AB s = new AB("Hello!",“world”);System.out.println(s.toString( ));}} class AB {String s1;String s2;AB( String str1 , String str2 ){ s1 = str1; s2 = str2; }public String toString( ){ return s1+s2; }} A: Hello!world B: worldHello!
- 下面的哪些程序片断可能导致错误?( ) A: String s=”Hello”; String t=,,World"; String k=s+t; B: String s=,,Hello";String t;t=s[3]+"one"; C: String s="Hello,,;String standard = s.tollpperCase(); D: String s="Hello World”;String t=s-”World”;
- String s1="Hello";String s2="World";System.out.println(s2+s1);运行的结果是? A: HelloWorld B: Hello World C: WorldHello D: World Hello