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.
Type | Value | Expression | |
---|---|---|---|
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?") |