UPDATED ACTUAL Questions and
CORRECT Answers
Consider the following variable declarations.
int a = 5;
int b = 4;
double x = 5;
double y = 4;
Which of the following expressions would evaluate to the number, 1?
1. (int) x / y
2. a / b
3. a % b - CORRECT ANSWER - All of them. (1 , 2, and 3)
Consider the following variable declarations.
1. double x = (int) 3.4
2. int y = (int) , 5
3. String z = new String(" ") - CORRECT ANSWER - 1 and 3
Consider String a below. Which of the following would create a new String with the value,
"ram"?
String a = new String ("Java Program"); - CORRECT ANSWER - String b =
a.substring(9);
, Better code will NOT type in a static number to produce words near the end of the String and
instead, uses length. Which of the following will result in "ram" in a better way than #2 did? -
CORRECT ANSWER - String b = a.substring(a.length()-3);
What special type of data is identified it has methods , unlike primitive data? Another giveaway
that this is not primitive data is that variables of this type begin with a capital letter. - CORRECT
ANSWER - Objects
Consider the code segment below. What is the result that is printed on the screen?
String six = new String ("Question 6");
int find = six.indexOf("q");
find = find + 2;
System.out.println(find + six.indexOf("t"); - CORRECT ANSWER -5
What is the value stored in z by the end of the code segment?
int x = 3;
int y = 6;
double z = x + y / 2; - CORRECT ANSWER - 6.0
What is the value stored in c by the end of the code segment?
int a = 2;
double b = 3;
int c = (int) b / a * (int) b; - CORRECT ANSWER -3
The output of the program below is not always the same. What is the range of numbers that
could've been printed?
String word = new String ("Value");
int random = (int) (Math.random() * word.length() + 1);