AP Computer Science A S1
14
(2+3)^2-(15/3)*2-1 =
7
(20 + 3) / 3 =
True
(T/F) The following contains error: String genderString = in.nextChar();
164
2 + 24/12*(2+1)^4 =
1
2 + 2^3-24/6*2 -1 =
49
6^2+10/2 +2*4 =
oldString.substring(15,18);
Complete the code below that would store "awe" to the variable newString? String oldString = "Programming is awesome!"; String newString = ?????
return inches /12;
Complete the code block: public static int convertToFeet( int inches) { ************* }
int (integer)
Given the following code segment: int x = 14; int y= 8; What is the data type for the expression (x/y)?
double
Given the following: double x = 22.9; double y = 9.8; What is the data type of the value of the expression (x/y)?
17
Given: int d = 14 - 22/5 %4 +3; What is the value of d?
3
Given: int m = 23; int n = 5; int p = m % n; What is the value of p?
6
Given: int x= 65; int y= 10; int z= x/y; What is the value of z?
9
How many times will the following code repeat? int flipCount = 1; while(flipCount < 10) { flipCount++; }
1
String greet1 = "Good Morning"; String greet2 = "Good Afternoon"; int result; if (greet1.compareTo(greet2) > 0) result = 1; else if (greet1.compareTo(greet2) <0) result = -1; else result = 0; What is result value?
-1
String msg = "Java a great part of my day"; int num = msg.indexOf("Great"); what is the value of num?
a Keys
String s = "Florida Keys"; what is the value of s.substring(6); ?
2
String str = "Always pass on what you learn."; What is the value of str.indexOf("way"); ?
-1
String str = "Florida Keys"; What is the value of str.indexOf("keys"); ?
12
String str = "It compiled!"; What is the value of str.length() ?
-1
String str = "Truly wonderful"; What is the value of str.indexOf("full"); ?
false
String word1 = "Earth"; String word2 = "earth"; What is the value of word1.equals(word2); ?
a negative integer
String word1 = "busy"; String word2 = "be"; word2.compareTo(word1) is . . .
185
What does 271 represent in the decimal system?
101
What does decimal 257 equal in the hexadecimal system?
21
What does the binary number 10101 represent in the decimal system?
101101
What does the hexadecimal number 2D represent in the binary system?
147
What does the hexadecimal number 93 represent in the decimal system?
3
What is printed as a result of the program? String word = "programming"; System.out.println(word.indexOf('g'));
String
What is the data type of the return value of the String class substring() method with one parameter?
15
What is the result of the following: int x = 10; if(x+1 < 20) x+=5; System.out.println(x);
int
What is the return type of the String class compareTo() method?
2.0
What is the value of: double d = (double) (14/5);
3.0
What is the value of: double d = 10/3;
5.0
What is the value of: double dNum = 5;
6.0
What is the value of: double x = (int)2.5 * 3;
0
What is the value of: int i = 55/100;
38
What is the value of: int iNum = (int)38.78;
Error: incompatible types
What is the value of: int vNum = 2.02;
7
What is the value of: int x =7;
2
What is the value of: int y = 14/5;
The cast is applied to late. The integer result will be cast to a double always ending in 0.
What is wrong with the following code: int base = 7; int height = 15; double area = (double) ((height * base)/2);
hri
What will be displayed after the code is executed? String name = Christopher Marlow"; int x = name.indexOf("t")/3; String newStr = name.substring(x, x+3); System.out.print(newStr);
12
What will be displayed after the code is executed? String str = " I ate chocolate."; String newStr = str.replace("ate", "8"); System.out.print(newStr.length());
lo
What will be displayed on the screen after the code is executed? String name "Marlow"; String newStr = name.substring(3,5); System.out.print(newStr);
25
What will be on screen when the code runs? int num = 5; num += 20; System.out.prinl(num);
2 7 12 17
What will be printed: for(int j = 0; j <21; j++) { if (j % 5 == 2) System.out.println(j + " "); }
0 4 8 12 16 20
What will the output be? int num = 0; while (num < 20) { System.out.println(num + " "); num +=4; } System.out.println(num);
C
Which contains error? a. System.out.print("please enter your age in years:"); b. String userAge = in.next(); c. int ageInYears = integer.ParseInt(userAge);
B
Which contains error? a. import java.util.Scanner; b. public static void Main(String [] args) c. Scanner in = new Scanner(System.in);
B
Which of the following contains error: a. char gender = genderString.charAt(0); b. boolean isFemale = gender == "F"; c. int age = Integer.parseInt(ageString);
B & C
Which of the following does NOT contain error? a. Scanner in = new Scanner(System.in.print); b. System.out.print("Please enter your name:"); c. String firstName = in.next();
A
Which of the following will NOT correctly increment the value by one of a previously initialized variable counter? a. counter +1; b. counter++; c. counter = counter +1; d. counter +=1;
C
Which of the following will be true: a. "Joseph".equals("JOSEPH") b. "Joseph".compareTo("JOSEPH") == 0 c. "Jose".compareTo("Joseph") < 0
A & B
Which of the following will evaluate to false? a. 12 < 12.0 b. 12 != 12.0 c. 12 == 12.0
A & B
Which will evaluate to false? a. 11 / 7 > 1.0 b. 11 / 7.0 == 1.0 c. (int) (11.0/7.0) == 1.0
if (a != b) && (b > c)
if (a != b) { ** code block if (b > c) { ** code block } } What is the same as the above statement?
10
int number = 6 +19 % 5; is equal to. . .
A
int result = 95; if (result >= 90) grade = "A"; if (result >= 80) grade = "B"; else grade = "E"; What is the value of grade?
13.0
int x = 6; int y =2; double z = 3.0; System.out.print(5+ x/y*z-1);
7.0
what is the value of: double b = (int) (2.5 * 3);
0.0
what is the value of: double h = 55/100;
(c <= d)
which is equivalent to !(c > d)?