AP Computer Science A Final Exam Review

Ace your homework & exams now with Quizwiz!

Consider the following code segment and class. Student mack = new Student();System.out.println(mack.getAge());public class Student{ private int age; public int getAge() { return age; }} What is printed as a result of executing the code segment?

0

Evaluate: Math.sqrt(16) * Math.max(Math.abs(-5), Math.abs(-3))

20.0

(2 - 6) / 2 + 9

7

What data type should you use for a shoe size like 8.5?

double

State what's printed: int a = 84, a= 1; boolean tf = true; System.out.println(tf && !tf);

false

State what's printed: int a = 84, a= 1;boolean tf = true;System.out.println(tf && !tf);

false

State what's printed: int a = 84, b = 1;boolean tf = true;boolean boo = (tf && ((a - 83) != b)); System.out.println(boo && tf || !tf );

false

Determine the output of the following code segments. Write no output if there is no output. int i = 2;int j = 3;if (i > j){ System.out.println ("You got it!");}

no output

Determine the output of the following code segments. Write no output if there is no output. int i = 2;int j = 3;if (j + 9 == i){ System.out.println ("You got it!");}

no output

Consider the following declarations. int valueOne, valueTwo; Assume that valueOne and valueTwo have been initialized. Which of the following evaluates to true if valueOne and valueTwo contain the same value?

valueOne == valueTwo

State what is printed. int x = 40; int y = 4; System.out.println(2 + 8 * y / 2 - x);

-22

What is the value of the expression: -5 * 9 / 10 + 10 * 5 / 9

1

What is the value of pos after the following code executes? String s1 = "abccba";int pos = s1.indexOf("c");

2

Consider the following method. public void numberCheck(int maxNum){ int typeA = 0; int typeB = 0; int typeC = 0; for (int k = 1; k <= maxNum; k++) { if (k % 2 == 0 && k % 5 == 0) typeA++; if (k % 2 == 0) typeB++; if (k % 5 == 0) typeC++; } System.out.println(typeA + " " + typeB + " " + typeC)} What is printed as a result of the call numberCheck(50) ?

5 25 10

Consider the following method. public int someCode(int a, int b, int c){ if ((a < b) && (b < c)) return a; if ((a >= b) && (b >= c)) return b; if ((a == b) || (a == c) || (b == c)) return c;} Which of the following best describes why this method does not compile?

It is possible to reach the end of the method without returning a value.

What is the data type of the following literal? "B"

String (s uppercase)

Consider the following code segment. for (int k = 1; k <= 100; k++){ int n1 = (int) Math.random(); int n2 = (int) Math.random() * 4; boolean boo1 = n1 == n2; System.out.print(boo1 + " ");} What is printed as a result of executing the code segment?

The code segment always prints true.

What data type holds true/false values?

boolean

Write a single statement that will store a true in the boolean variable tf only if boo is negative.

boolean tf = boo < 0;

What is the data type of the following literal? 'A'

char

Consider the following code segment. String s1 = "Djakarta"; String s2 = s1.substring(3, 7); String s3 =s1.substring(3); System.out.println(s2); System.out.println(s3); What will be output when the code segment executes?

kart karta

What are the two varieties of data in Java?

objects and primitive

Consider the following code segment. int k = 1;while (k < 20){ if ((k %3) == 1) System.out.print(k + " "); k++;} What is printed as a result of executing this code segment?

1 4 7 10 13 16 19

Consider Java's two overloaded substring methods. String substring(int from, int to)String substring(int from) Given a string s, when will returns s.substring(p, q) and s.substring(p) be the same String value?

Anytime, as long as q is equal to s.length()

What is the data type of the following literal? "fooled you"

String

New objects can be created by using the new operator with an appropriate constructor.

True

What are the values of a and b after the for loop finishes? int a = 10;int b = 3;int t = 0;for (int i = 1; i < 4; i++){ t = a; a = i + b; b = t - i;}

a = 5 and b = 8

A ______ is a note written to a human reader of a program.

comment

Which of the following is legal?

x=9

Consider the following code segment. for (int k = 0; k < 20; k = k + 1){ if (k % 2 == 1) System.out.print((k + 1) + " ");} What is printed as a result of executing the code segment?

2 4 6 8 10 12 14 16 18

Consider the following code segment. int x = /* some integer greater than zero */int n = 100;if (x < 1000){ if (x > 1000) n = 200; else n = 300;}else{ if (x < 1000) n = 400; else n = 300;}System.out.println(n); What is printed as a result of executing the code segment?

300

Consider the following code segment. The code is intended to read nonnegative numbers and compute their product until a negative number is read; however, it does not work as intended. (Assume that the readInt method correctly reads the next number from the input stream.) int k = 0;int prod = 1;while (k >= 0){ System.out.print("enter a number: "); k = readInt(); // readInt reads the next number from input prod = prod * k;}System.out.println("product: " + prod); Which of the following best describes the error in the program?

The negative number entered to signal no more input is included in the product.

Consider the following code segment. String s1 = "Computer Science";String s2 = "Computer";String s3 = "Science";System.out.print(s1.indexOf(s2));System.out.print(" ");System.out.println(s1.indexOf(s3)); What will be output when the code segment executes?

0 9

Consider the following code segment. String str = "012345";for (int i = 0; i < str.length() - 1; i++){ System.out.print(str.substring(i, i+2));} What is printed as a result of executing this code segment?

0112233445

Examine this code: String str = "Hello World!" ; What is the index of the character 'e' ?

1

Evaluate: Math.sqrt(76 + 45)

11.0

Consider the following code segment for(int i = 0; i <= 3; i++){for(int j = 1; j <=5; j+=2){System.out.println("*");}} How many times will a '*' be printed?

12

Consider the following code segment. String str = "Hello World!"; System.out.println(str.length()); What is printed as a result of executing the code segment?

12

What is the value of sum after the following code fragment is executed? int sum = 0, x = 1;while (sum < 10 && x <= 5){ sum += 2 * x; x++;}

12

Which of the following will result in an error?

12 + (13 + 7)/2 ) * 4

Consider the following code segment. String str = "Hello World!";System.out.println(str.substring(9)); What is printed as a result of executing the code segment?

1d!

Consider the following code segment. String test = "This is a test."; System.out.println(test.indexOf("is")); What is printed as a result of executing the code segment?

2

Evaluate: Math.abs(2 + -4)

2

How many different values can a boolean variable hold?

2

Consider the following method. /** Precondition: p > 0 */public static int method0201(int p){ int count = 1; for (int q = 1; q < p; q++) { count += count; } return count;} What value is returned as a result of the fall method0201(n) ?

2^(n - 1)

State what is printed. int a = 100; int b = 200; b/=a; System.out.println(b + 1);

3

Consider the following code segment. String s1 = "Queen Mary"; String s2 = "1936 Queen Mary"; String s3 = "Queen Elizabeth"; System.out.print(s2.indexOf(s1) + " "); System.out.println(s1.indexOf(s3)); What will be output when the code segment executes?

5 -1

Consider the following code segment. int p = 10;int q = 5;while (q != 0 && p/q > 0){ p--;System.out.println(p + " " + q); q--;} What is the last output when the segment executes?

5 1

Consider the following two methods. /** Precondition: n1 > 0 * n2 > 0 */public static int method0207a(int n1, int n2){ int temp = method0207b(n1, n2); return n1 / temp * n2;}/** Precondition: p > 0 * q > 0 */public static int method0207b(int p, int q){ int rem = 1; int k = 0; while (rem != 0) { rem = p % q; if (rem == 0) { k = q; } else { p = q; q = rem; } } return k;} What value is returned as a result of the call method0207a(30, 45) ?

90

What sort of thing is "Happy Days" in the following: String str = "Happy Days";

A String literal

Consider the following method. if ((a < 0) && (b > 0)){if (a > b)System.out.println("A");elseSystem.out.println("B");}else if ((b < 0) || (a < 0))System.out.println("C");elseSystem.out.println("D"); What is printed if a = 3 and b = -2?

C

What is displayed after the following code fragment is executed? int n = 4;int k, fact = 1;for (k = n; k >= 1; k++) fact *= k;System.out.println(n + "! = " + fact);

Error, this is an infinite loop.

Consider the following code segment. int value = 15;while (value < 28){ System.out.println(value); value++;} What are the first and last numbers output by the code segment?

First: 15 Last: 27

Consider the following code segment. String s1 = "MADAM";String s2 = "";for (int k = 0; k < s1.length(); k++){ s2 += s1.substring(k); s2 += " ";}System.out.println(s2);

MADAM ADAM DAM AM M

Write a Java formula using the Math class for: Distance = |val1 - val2|

Math.abs(val1-val2)

Consider the following code segment. int sum = 0;int k = 1;while (sum < 12 || k < 4) sum += k;System.out.println(sum); What is printed as a result of executing the code segment?

Nothing is printed due to an infinite loop.

Consider the following code segment. for (int k = 1; k <= 100; k++){ int n1 = (int) Math.random() * 2; int n2 = (int) Math.random() * 2; boolean boo1 = n1 == n2; System.out.print(boo1 + " ");} What is printed as a result of executing the code segment?

The code segment always prints true.

What will be the value of r? String r = "Saturday Night Live"; r = r.substring(5, 8);

day

Which of the following is the most acceptable way of naming a variable?

groovyDude

What is another way to write p = p - 1;?

p--;

Create the heading for class called Skeleton.

public class Skeleton{}

Which of the following is the correct header line for the main method in Java?

public static void main (String args [])

Consider the following static method. public static int calculate(int x){ x = x + x; x = x + x; x = x + x; return x;} Which of the following can be used to replace the body of the calculate so that the modified version of calculate will return the same result as the original version for all x?

return 8 * x;

What will be the value of c? String c = "The Partridge Family"; c = c.substring(8);

ridge Family

What is the camel case variable name for a variable that represents a shoe size?

shoeSize

What is the data type of the following literal? "fooled you"

string

What is the purpose of wrapper classes?

to convert primitive type variables into objects containing the equivalent information.

What is the camel case variable name for a variable that represents the top score?

topScore

State what's printed: int a = 84, b = 1;boolean tf = true;System.out.println((a != 1) || tf || (a == b));

true

What are the two possible values for a boolean variable?

true and false

The boolean expression (A || B) || !(A || B) evaluates to

true in all cases.

The boolean expression !(A || B) evaluates to

true whenever both A is false and B is false

The boolean expression (A || B) && (!A || !B) evaluates to

true whenever only A is true or only B is true.

Evaluate: Math.ceil(115.8)

116.0

Consider the following code. if (value < 0 || value > 100)System.out.println("true");elseSystem.out.println("false"); Given that value is an integer, which of the following code segments would have the same output as the code above? I. if (value < 0){if (value > 100)System.out.println("true");elseSystem.out.println("false");}elseSystem.out.println("false");II. if (value < 0)System.out.println("true");else if (value > 100)System.out.println("true");elseSystem.out.println("false");III. if (value >= 0)System.out.println("false");else if (value <= 100)System.out.println("false");elseSystem.out.println("true");

II only (check this)

The following code stores a 20 in the variable num; double num = 61/3; What small change can you make to this single line of code to make it produce the "real" answer to the division?

double num = (double) 61/3;

Write a series of statements which acquires the length of name and stores it in a variable named len. You must first declare len. String name = "SpongeBob SquarePants";

int len; len = name.length();

On a single line of code declare x, y, and z all to be an integer data type.

int x, y, z;

Which of the following is equivalent to !(a && (c < d))

!a || (c >= d)

The classes that convert primitives to objects are called _____ classes

wrapper

Evaluate: Math.min( 8, 3 + 2 )

5

What are the two steps that take place when an assignment statement is executed?

(i) Evaluate the Expression, and (ii) Store the value in the variable.

Which of the following would return a random int from 1 to 10 inclusive?

(int)(Math.random()*10)+1

Consider the following code segment. int n = <some integer greater than zero>int count = 0;int p = 0;int q = 0;for (p = 1; p < n; p++) for (q = 1; q < n; q++) count++;System.out.println(count); What is the value of count when the code finishes executing?

(n - 1)^2

Consider the following code segment which is intended to assign true to between if x is between lower and upper, inclusive, and false otherwise. Assume lower <= upper and all values have been initialized. int x;int lower;int upper;boolean between;boolean = /*missing code*/

(x >= lower) && (x <= upper);

Consider the following code segment. for (int r = 3; r > 0; r--){ int c; for (c = 1; c < r; c++) { System.out.print("-"); } for (c = r; c <= 3; c++) { System.out.print("*"); } System.out.println();} What is printed as a result of executing the code segment?

- - * - * * ***

Consider the following code segment. String s1 = "A"; String s2 = "H"; System.out.print(s1.compareTo("B")); System.out.print(" "); System.out.println(s2.compareTo("B")); What is printed as a result of executing the code segment?

-1 6

Consider the following code segment and class. Student mack = new Student(11);System.out.println(mack.getAge());public class Student{ private int age;public Student(int a) { age = age; } public int getAge() { return age; }} What is printed as a result of executing the code segment?

0

Consider the following code segment and class. Widget w1 = new Widget(66);Widget w2 = new Widget(77);System.out.println(w1.getWidgets() + " " + w2.getWidgets());System.out.println(w1 + " " + w2);public class Widget{ private int numWidgets; public Widget(int numWidgets) { numWidgets = numWidgets; } public int getWidgets() { return numWidgets; }}

0 0 Widget@112383b3 Widget@1a9a8e40

Consider the following code segment. for (int outer = 0; outer < n; outer++){ for (int inner = 0; inner <= outer; inner++) { System.out.print(outer + " "); }} If n has been declared as an integer with the value 4, what is printed as a result of executing the code segment?

0 1 1 2 2 2 3 3 3 3

Consider the following code segment. int k = 0;while (k < 10){ System.out.print((k % 3) + " "); if ((k % 3) == 0) k = k + 2; else k++;} What is printed as a result of executing the code segment?

0 2 0 2 0 2 0

What is the value of the int variable d after the following statement is executed? for (d = 1; d < 567; d *= 10);

1000

Consider the following code segment. int x = 0;for (int y = 1; y <= 12; y++){ while (x <= y) { if (x % 2 == 0) x += 2; else y -= 2; }}System.out.println(x); What is printed as a result of executing the code segment?

14

What is the value of sum after the following code fragment is executed? int sum = 0, x = 1;while (sum < 20 && x <= 5){ sum += 2 * x; x++;}

20

int x = /* some integer greater than zero */int n = 100;if (x < 1000){ if (x > 1000) n = 200; else n = 300;}else{ if (x < 1000) n = 400; else n = 300;}System.out.println(n); What is printed as a result of executing the code segment?

300

Consider the following code segment. int num = 2574;int result = 0;while (num > 0){ result = result * 10 + num % 10; num /= 10;}System.out.println(result); What is printed as a result of executing the code segment?

4752

Consider the following code segment. int num = 2574;int result = 0;while (num > 0){ result = result * 10 + num % 10; num /= 10;}System.out.println(result); What is printed as a result of executing the code segment? Correct answer:

4752

Consider the following code segment and method. int x = 5;x = method0205(x);System.out.println(x);public static int method0205(int n){ for (int k = n; k <= 10; k++) n += k; return n;} What is printed as a result of executing the code segment?

50

Consider the following code segment. int a = 24;int b = 30;while (b != 0){ int r = a % b; a = b; b = r;}System.out.println(a); What is printed as a result of executing the code segment?

6

Consider the following program. public class DS0210{public static void main(String args[]) { samba(65.0);}public static void samba(int k) { System.out.println(k);}public static void samba(double k) { System.out.println(k);}public static void samba(char k) { System.out.println(k);} public static void samba(String k) { System.out.println(k);}} What is printed as a result of executing the program?

65.0

What is output by the following code? int a = 90, b = 8; if( (a<b) || (a-12>b) ) a = b; System.out.println(b++);

8

What is output by the following code? int a = 90, b = 8;if( (a<b) || (a-12>b) ) a = b;System.out.println(b++);

8

Consider the following code: System.out.print("Fire");System.out.println(" Ants"); Which of the following is actually printed?

Fire Ants

Consider the following code segment. int result= 99;if (num1 == num2) {result = 0:}else if (num1 > num2) {result = 1;}else {result = -1;}System.out.println(result); Which of the following code segments will print the same result as the code above no matter what integers are stored in num1 and num2? I.int result = 99;if (num1 == num2) {result = 0;}else {if (num1 > num2) {result = 1;}else {result = -1;}}System.out.println(result);II.int result = 99;if (num1 == num2) {result = 0;}if (num1 >= num2) {result = 1;}else {result = -1;}System.out.println(result); III.int result = 99;if (num1 == num2) {result = 0;}if (num1 > num2) {result = 1;}if (num1 < num2) {result = -1;}System.out.println(result);

I and III

Consider the following code segments. I. int k = 1; while (k < 20) { if (k % 3 == 1) System.out.print(k + " "); k = k + 3; }II. for (int k = 1; k < 20; k = k + 3) { if (k % 3 == 1) System.out.print(k + " "); }III. for (int k = 1; k < 20; k = k + 3) { System.out.print( k + " "); } Which of the code segments above will produce the following output? 1 4 7 10 13 16 19

I, II, and III

Consider the following variables that appear in a program representing student information. int assignmentsCompleted; double testAverage; boolean isPassing; A student can pass a programming course if at least one of the following conditions is met. The student has a test average that is greater than or equal to 90. The student has a test average that is greater than or equal to 75 and has at least 4 completed assignments. Consider the following proposed implementations of the conditions. I. if (testAverage >= 90) isPassing = true; else if (testAverage >= 75 && assignmentsCompleted >= 4) isPassing = true; elseisPassing = false; II. boolean pass = false; if (testAverage >= 90) pass = true; else if (testAverage >= 75 && assignmentsCompleted >= 4) pass = true; isPassing = pass; III. isPassing = (testAverage >= 90) || (testAverage >= 75 && assignmentsCompleted >= 4); Which of the implementations will work correctly assuming that the variables have been initialized?

I, II, and III

The following table shows several examples of input and output values. Input value Output value 3 30 6 60 7 7 8 80 9 90 11 11 12 120 14 14 16 160 Which of the following code segments could be used to produce the output values using the input values for n? I. if ((n % 3 == 0) && (n % 4 == 0))System.out.println(n * 10);elseSystem.out.println(n);II. if ((n % 3 == 0) || (n % 4 == 0))System.out.println(n * 10);elseSystem.out.println(n);III. if (n % 3 == 0)if (n % 4 == 0)System.out.println(n * 10);elseSystem.out.println(n);

II only

The following statements display 21 instead of the expected 121. Why? int m, q = 1, sum = 0;for (m = 0; m <= 10; m++)q = 2 * m + 1;sum += q;System.out.println(sum);

Missing Braces

What is the relationship between an object, method, and a class.

Objects are defined in a class and methods perform a task.

Consider the following code segment. int x = /* some integer value */ ;int y = /* some integer value */ ;boolean result = (x < y);result = ( (x >= y) && !result ); Which of the following best describes the conditions under which the value of result will be true after the code segment is executed?

Only when x >= y

Which of the following is NOT the name of a Java primitive data type?

String

What is output by the following? int x = 8, y = 5;if( !(x == y) ){ System.out.println("Sunday, Monday");}else{ System.out.println("Happy Days!");}

Sunday, Monday

int x = 8, y = 5;if( !(x == y) ){ System.out.println("Sunday, Monday");}else{ System.out.println("Happy Days!");}

Sunday, Monday

Consider the following code segment. for (int k = 1; k <= 100; k++){ int n1 = (int)(Math.random() * 10); int n2 = (int)(Math.random() * 10); boolean boo1 = n1 == n2; System.out.print(boo1 + " ");} What is printed as a result of executing the code segment?

There is a 1 in 10 probability that the code segment prints true.

Sometimes, a for loop's "initialization" statement may be empty, as in int i = keyboard.readInt(); for ( ; i < n; i++) ...

True

State what is printed: int a = 84, b = 1;boolean boo = a != b; System.out.println(boo);

True

State what's printed: int a = 84, b = 1; boolean tf = true; System.out.println((a != 1) || tf || (a == b));

True

Determine the output of the following code segments. Write no output if there is no output. int i = 2; int j = 3; if (j != i) { System.out.println ("You got it!"); }

You got it!

What is the value of a, b, and c after the following code segment? int a = 45;int b = 10;int c = a % b;if (c != 0){ a = b; b = c;}

a = 10, b = 5, c = 5

Examine this code: String myString = ""; What value is contained in myString?

a String reference

What are the final values of a, b, and c? int a = 4, b = 9, c = -3;if (a >= b) if (c < b) a = b + c; else c = a - c;else if (c < a) b = c - b;

a= 4, b= -12, c= -3

Consider the following code segment. String bigString1 = "";String bigString2 = "";String str = "Annapolis";int k = 3;while (k < str.length()){ bigString1 += str.substring(k, str.length()); bigString2 += str.substring(k); k++;}System.out.println(bigString1);System.out.println(bigString2); What is printed as a result of executing the code segment?

apolispolisolislisiss apolispolisolislisiss

What data type should you use to record if it is raining or not?

boolean

In an if statement the condition is called the

boolean expression

What is the value of str2 after the following code executes? String s1 = "helicopter"; String s2 = s1.substring(4, 7);

cop

Consider the following code fragment: int count = 0;double x = <someValue> ;double a = <someValue>;while (count < 100 && (x * x * x - a) > 0.01){ x = (1.0 / 3.0) * (2 * x + a / (x * x)); count++;} Which of the following conditions must be true after this code has been successfully executed?

count >= 100 || (x * x * x - a) <= 0.01

What data type should you use to represent the amount of money in a bank account?

double

What data type should you use to represent the average grade for a course?

double

What data type would you use to store this number? 189.24

double

Consider the following output. 1 1 1 2 3 1 2 3 4 1 2 3 4 5 1 2 3 4 5 6 1Which of the following code segments will produce the output shown above?

for (int j = 1; j <= 6; j++){ for (int k = 1; k <= j; k++) System.out.print(" " + k); System.out.println();}

for(int i = 9; i < 11; i +=2){ System.out.println(i + ",");} What is the step expression?

i += 2

What method would you use to find the location of "free" in the string "freedom"?

indexOf()

Write code that will calculate and print the square root of 435.61.

System.out.println(Math.sqrt(435.61));

What are the final values of a, b, and c? int a = 4, b = -9, c = 7;if (a > b && b > c) if (b < a) b = -b; else a = -a;else if (a > b || b > c) if (a < c) c = -c; else if (! (c > b)) b = -a;

a= 4, b= -9, c= -7

Which of the following is a keyword?

boolean

What is the camel case variable name for a variable that represents the last score?

lastScore

Consider the following code segment which is intended to assign true to between if x is between lower and upper, inclusive, and false otherwise. Assume lower <= upper and all values have been initialized. int x; int lower; int upper; boolean between; boolean = /*missing code*/ Which of the following can be used to replace /* missing code */ so that between will hold the correct value.

(x >= lower) && (x <= upper);

What is the value of len after the following executes? String s1 = "Love you!"; int len = s1.length();

9

State what is printed. System.out.println((double)(90/9));

10.0

A teacher put three bonus questions on a test and awarded 5 extra points to anyone who answered all bonus questions correctly and no extra points otherwise. Assume that the boolean variables bonusOne, bonusTwo, and bonusThree indicate whether a student has answered the particular question correctly. Each variable was assigned true if the answer was correct and false if the answer was incorrect. Which of the following code segments will properly update the variable grade based on a student's performance on the bonus questions? I. if (bonusOne && bonusTwo && bonusThree) grade += 5; II. if (bonusOne || bonusTwo || bonusThree) grade += 5; III. if (bonusOne) grade += 5; if (bonusTwo) grade += 5; if (bonusThree) grade +=5;

I only

A teacher put three bonus questions on a test and awarded 5 extra points to anyone who answered all bonus questions correctly and no extra points otherwise. Assume that the boolean variables bonusOne, bonusTwo, and bonusThree indicate whether a student has answered the particular question correctly. Each variable was assigned true if the answer was correct and false if the answer was incorrect. Which of the following code segments will properly update the variable grade based on a student's performance on the bonus questions? I. if (bonusOne && bonusTwo && bonusThree)grade += 5;II. if (bonusOne || bonusTwo || bonusThree)grade += 5;III. if (bonusOne)grade += 5;if (bonusTwo)grade += 5;if (bonusThree)grade +=5;

I only

Consider the following variables that appear in a program representing student information. int assignmentsCompleted;double testAverage;boolean isPassing; A student can pass a programming course if at least one of the following conditions is met. The student has a test average that is greater than or equal to 90. The student has a test average that is greater than or equal to 75 and has at least 4 completed assignments. Consider the following proposed implementations of the conditions. I. if (testAverage >= 90)isPassing = true;else if (testAverage >= 75 && assignmentsCompleted >= 4)isPassing = true;elseisPassing = false;II. boolean pass = false;if (testAverage >= 90)pass = true;else if (testAverage >= 75 && assignmentsCompleted >= 4)pass = true;isPassing = pass;III. isPassing = (testAverage >= 90) || (testAverage >= 75 && assignmentsCompleted >= 4); Which of the implementations will work correctly assuming that the variables have been initialized?

I, II, and III

Consider the following code segment. Assume value is an int. if (value < 0) || value < 100)System.out.print("Not in range");elseSystem.out.print("In range"); Consider the following code segments that could be used to replace the code. I. if (value < 0){if (value > 100)System.out.print("Not in range"); elseSystem.out.print("In range");}elseSystem.out.print("In range");II. if (value < 0)System.out.print("Not in range"); else if (value < 100)System.out.print("Not in range");elseSystem.out.print("In range");III. if (value >= 0)System.out.print("In range"); else if (value <= 100)System.out.print("In range");elseSystem.out.print("Not in range"); Which of the replacements will have the same behavior as the original version of the code segment?

II only

What are the three primitive data types that will be tested on the AP Exam?

double boolean int

On a single line of code declare x, y, and z to be double and on that same line initialize them all to be 3.14.

double x = 3.14, y = 3.14, z = 2.14;

Write a formula that will find the distance between two values, num1 and num2 by taking the absolute value of their difference. Assign the answer to double x.

double x = Math.abs(num1-num2)

Show the basic skeleton of an if - else structure.

if( ) { } else { }

The ________ method is where a program starts running.

main

What is the output from the following code? String s = "Computer Science is fun!"; String s1 = s.substring(0, 8); String s2 = s1.substring(1); String s3 = s2.substring(1, 3); System.out.println(s3);

mp

What is returned by a method of type void?

nothing

The boolean expression !(A || B) evaluates to

true whenever both A is false and B is false.

Consider the following declarations. int valueOne, valueTwo; Assume that valueOne and valueTwo have been initialized. Which of the following evaluates to true if valueOne and valueTwo contain the same value?

valueOne == valueTwo


Related study sets

Chapter 12 Software Development Security

View Set

Chapter 2 population review sheet

View Set

ap microeconomics self assessment ch 4

View Set

Marketing Chapter 13 (Sales Promo)

View Set

Marquis Leadership 8e Ch 1: Decision Making, Problem Solving, and Critical Thinking:, Marquis Leadership 8e Ch 2: Introduction to Management, Marquis Leadership 8e Ch 3: Developing Leadership, Marquis Leadership 8e Ch 19 Organizational, interpersonal...

View Set

Nursing Care of the Child with a Neurologic Disorder

View Set

Earth/Environmental Science - Released Form

View Set