Test 2
What is the output of Integer.parseInt("10", 2)?
2
What is the output of the following code? public class Test {public static void main(String[] args) {java.math.BigInteger x = new java.math.BigInteger("3");java.math.BigInteger y = new java.math.BigInteger("7");x.add(y);System.out.println(x);}}
3
What is the printout of the following code? String s1 = "Welcome to Java";String s2 = "Welcome to Java";System.out.println("s1 == s2 is " + s1 == s2);
?
What is the value of i, j, and d? Integer[] intArray = {1, 2, 3};int i = intArray[0] + intArray[1];int j = ++i + intArray[2];double d = ++j + intArray[0];
?
What is displayed by the following code?System.out.print("A,B;C".replaceAll(",;", "#") + " ");System.out.println("A,B;C".replaceAll("[,;]", "#"));
A,B;C A#B#C
What is displayed by the following code?public static void main(String[] args) {String[] tokens = "Welcome to Java".split("o");for (int i = 0; i < tokens.length; i++) {System.out.print(tokens[i] + " ");}}
Welc me t Java
What is the print out of the following code? String s = "Welcome to Java";s.replaceAll("a", "BB");System.out.println(s);
Welcome to Java
Assume s is "ABCABC", the method __________ returns a new string "aBCaBC".
s.replace("ABCABC", "aBCaBC"); s.replace('A', 'a');
What is the output of the following code? public class Test {public static void main(String[] args) {String s1 = new String("Welcome to Java!");String s2 = s1.toUpperCase(); if (s1 == s2)System.out.println("s1 and s2 reference to the same String object");else if (s1.equals(s2))System.out.println("s1 and s2 have the same contents");elseSystem.out.println("s1 and s2 have different contents");}}
s1 and s2 have different contents
What is the output of the following code? public class Test {public static void main(String[] args) {String s1 = new String("Welcome to Java!");String s2 = new String("Welcome to Java!"); if (s1 == s2)System.out.println("s1 and s2 reference to the same String object");elseSystem.out.println("s1 and s2 reference to different String objects");}}
s1 and s2 reference to different String objects
What is the output of the following code? public class Test {public static void main(String[] args) {String s1 = "Welcome to Java!";String s2 = s1; if (s1 == s2)System.out.println("s1 and s2 reference to the same String object");elseSystem.out.println("s1 and s2 reference to different String objects");}}
s1 and s2 reference to the same String object
Assume StringBuilder strBuf is "ABCCEFC", after invoking _________, strBuf contains "ABTTEFT".
strBuf.replace(2, 7, "TTEFT");
The following program displays __________. public class Test {public static void main(String[] args) {String s = "Java";StringBuilder buffer = new StringBuilder(s);change(buffer);System.out.println(buffer);}private static void change(StringBuilder buffer) {buffer.append(" and HTML");}}
Java and HTML
What is displayed by the following code?System.out.print("Hi, ABC, good".matches("ABC ") + " ");System.out.println("Hi, ABC, good".matches(".*ABC.*"));
false true
