Java: String Exercises 1

Name _______________________________________

(10 points) Given the following local variable declarations:

      String a = "abcde";
      String t = "12.5";
      int i = 2;

What is the type (String, int, or double) and value of the following expressions (or Unknown or ERROR)? Note: these are just expressions, and would have to be put into a statement to be legal Java.

TypeValueExpression
0___int_________5______i + 3
1______________________a
2______________________a.length()
3______________________a.length() / 2
4______________________a.indexOf("c")
5______________________a.substring(0, 2)
6______________________Double.parseDouble(t)
7______________________i + a
8______________________"x" + a + "x"
9______________________a.substring(a.indexOf("cd"), a.length())
10______________________"Goodbye".indexOf("B")
11______________________JOptionPane.showInputDialog(null, "Huh?")