AP Comp Review

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Assume that a and b have been defined and initialized as int values. The expression !(!(a != b) && (b > 7)) is equivalent to which of the following

(a != b) || (b <= 7))

int a = 9; int b = 5; while (a % b != 0) { int temp = a; a = b; b = temp % b; } System.out.println (b); What is the output?

1

What value is stored in result if int result = 13 - 3 * 6 / 4 % 3;

12

double x = 3.5467; int y = 5; y = (int)x; What is the value of y?

3

What is the range of the output of the following? System.out.println ((int)(Math.random() *20) + 5);

5 - 24

What is the output of the following: for (int i = 5; i <= 10*2; i+=5) { System.out.println (i + ' '); }

5 10 15 20

public static int mystery (int[] arr) { int x = 0; for (int k = 0; k < arr.length; k = k + 2) x = x + arr[k]; return x; } Assume that the array nums has been declared and initialized as follows. int[] nums = {3, 6, 1, 0, 1, 4, 2}; What value will be returned as a result of the call mystery (nums) ?

7

Which of the following will declare and create a String name that holds the value "Janice"? I. String name = "Janice"; II. String name = new String ("Janice"); III. String name; name = new String "Janice";

I, II, and III

public class Point { private double x; private double y; public Point() { x = 0; y = 0; } public Point (double a, double b) { x = a; y = b; } //There may be instance variables, constructors, and methods that are not shown. } public class Circle { private Point center; private double radius; /** Constructs a circle where (a, b) is the center and r is the radius. */ public Circle (double a, double b, double r) { /* missing code */ } } Which of the following replacements for /* missing code */ will correctly implement the Circle constructor? I. center = new Point(); radius = r; II. center = new Point(a, b); radius = r; III. center = new Point(); center.x = a; center.y = b; radius = r;

II only

public class SomeClass { private int myA; private int myB; private int myC; //Constructor(s) not shown public int getA() { return myA; } public void setB(int value) { myB = value; } } Which of the following changes to SomeClass will allow other classes to access but not modify the value of myC?

Include the method: public int getC() { return myC; }

What best describes the purpose of a class's constructor?

Initialize the fields of this instance of the class

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; }

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

Consider the following code segment. int num1 = 0; int num2 = 3; while ((num2 != 0) && ((num1 / num2) >= 0)) { num1 = num1 + 2; num2 = num2 - 1; } What are the values of num1 and num2 after the while loop completes its execution?

num1 = 6; num2 = 0;

What will the method String substring (int from, int to), which belongs to the String class, return?

returns a String beginning at from and ending at (to-1)


Kaugnay na mga set ng pag-aaral

chapter 42 self assessment questions

View Set

#14 Based on the research on goal setting, what types of goals are most effective and why?

View Set

Kitchen safety Culinary fundamentals

View Set

African American History (Kodi Roberts)

View Set