A: hello
B: world
C: helloworld
D: 没有输出
举一反三
- 以下程序的输出结果是 String s1="1",s2="2"; String s=s1+s2; System.out.println(s);
- 关于以下程序段,正确的说法是( ) 1 String s1=”abc”+”def” 2 String s2=new String(s1); 3.If(s1= =s2) 4.System.out.println(“= = succeeded”); 5.if (s1.equals(s2)) 6.System.out.println(“.equals() succeeded”);
- 下列代码片段执行结果是: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
- (10-8)关于以下程序段,正确的说法是( )。 1 String s1=”ac”+”def”; 2 String s2=new String(s1); 3 if(s1.equals(s2)) 4 System.out.println(“equals() succeeded”); 5 else if(s1==s2) 6 System.out.println(“== succeeded”);
- 以下要输出“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);
内容
- 0
以下代码共创建了几个对象?String s1=new String("hello");String s2=new String("hello");String s3=s1;String s4=s2; A: 2 B: 4 C: 1 D: 3
- 1
String s1="Hello";String s2="World";System.out.println(s2+s1);运行的结果是? A: HelloWorld B: Hello World C: WorldHello D: World Hello
- 2
执行下面代码后,将创建()个对象。String s1="hello";String s2=new String(s1); A: 0 B: 1 C: 2 D: 3
- 3
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!
- 4
【其它】写出并理解下列语句输出的结果 s = "hello" print(s[0]) print(s[4]) print(s[-1]) print(s[0:3]) print(s[0:4:2]) print(s[:]) print(s[:3]) print(s[::-1]) print(s[1:])