You are on page 1of 8

表單的頂端

1 (Points: 10.0)  
.
How do you convert a char, an array of characters, or a number to a string?

1. By valueOf method in the String class

2. By String.parseString() method
 
3. By convertTo method of the char, array or number

4. None of the above.

  Save and View Next  Next Question

表單的底部

2.
(Points: 10.0)     Suppose string s is created using new String(); what is s.length()?

4. None of the above.

  Save and View Next  Next Question

3.
(Points: 10.0)     There is some methods that can change the contents of the string. True
4.
(Points: 10.0)     What is the printout of the following code?

String s1 = "Welcome to Java";


String s2 = s1.replace("o", "abc");
System.out.println(s2);
1. Welcabcme tabc Java

  Save and View Next  Next Question

5.
(Points: 10.0)     Which line of the following program is wrong?

1 public class Test {


2  String text;
3
4  public void Test(String s) {
5   this.text = s;
6  }
7
8  public static void main(String[] args) {
9   Test test = new Test("ABC");
10   System.out.println(test);
11  }
12}

1.

  Save and View Next  Next Question

6.
(Points: 20.0)     Suppose that s1 ,and s2 are two strings, given as follows:

String s1 = "Welcome to Java";


String s2 = new String("Welcome to Java");

What are the results of the following expressions?

01? 02
s1 = = s2   s1.length()
True 15
s1.equals(s2) 03   s1.substring(5, 11) 04
True me to
05 06
s1.charAt(0)   s1.startsWith("Wel")
W Welcome to Java
07 08
s1.indexOf('j')   s1.toLowerCase()
-1 Welcome to java
09 10
s1.indexOf("to")   s1.lastIndexOf('a')
8 14

  Save and View Next  Next Question

7.
(Points: 10.0)     Consider the program below:

1 public class Test {


2  public static void main(String[] args) {
3   String s = "Java";
4   StringBuffer bf = new StringBuffer(s);
5   change(s, bf);
6
7   System.out.println(s);
8   System.out.println(bf);
9  }
10
11  private static void change(String s, StringBuffer bf) {
12   s = s + " and HTML"; //Java and HTML
13   bf.append(" and HTML");
14  }
15 }

1. What is the output of the statement 7?


2. What is the output of the statement 8?

1. Java and HTML


2. Java and HTML

  Save and View Next  Next Question


8.
(Points: 20.0)     Suppose that s1 and s2 are given as follows:

StringBuffer s1 = new StringBuffer("Java");


StringBuffer s2 = new StringBuffer("HTML");

Show the value of s1 after each of the following statement. Assume that the following
statements are independent.

01 02
s1.append(" is fun");   s1.deleteCharAt(3);
Java is fun Jav
03 04
s1.append(s2);   s1.delete(1, 3);
JavaHTML Ja
05 06
s1.insert(2, "is fun");   s1.reverse();
Jais funva avaJ
07 08
s1.equals(s2);   s1.replace(1, 3, "Computer");
False JComputervComputer
09 10
s1.charAt(2);   s1.substring(1, 3);
v av
11 12
s1.length();   s1.substring(2);
4 v

  Save and View Next 

You might also like