Exercise 9.5
- Suppose that we are given the declarations
String s;
String t = null;
String u = "";
String v = " ";
State, with reasons, what would occur if the program containing these
declarations attempted to print the value of each expression.
a. s.length()
b. t.length()
c. u.length()
d. v.length()
- Given the declaration
String [] names = new String [10];
state, with justification, the result of each statement.
- System.out.println(names[0]);
- System.out.println(names.length);
- System.out.println(names.length());
- System.out.println(names[0].length());
- Using the table on page 600 where necessary, determine what would
be printed by each statement.
- System.out.println("" + '$' + '2');
- System.out.println('$' + '2');
- System.out.println('$' + 2);
- System.out.println("$" + '2');
- System.out.println("$" + 2);
- System.out.println('$' + '2' + ".00");
- Write a method whose heading is
public static String changeFirst (String s, char oldChar, char newChar)
The method should return a string in which the leftmost occurrence
of oldChar in s is replaced by newChar. If oldChar does not appear
in s, the method should simply return s.
| |