Which statement about parameters is false



SEMESTER EXAM AP COMPUTER SCIENCE

1. A cast is required in which of the following situations?

a) storing an int in an int

b) storing an int in a double

c) storing a double in a double

d) storing a double in an int

e) all of the above require casts

2 . If x is an int and y is a double, all of the following are legal except which assignment statement?

a) y = x;

b) x = y; I would need to cast x = (double)y;

c) y = (double) x;

d) x = (int) y;

e) all of the above are legal

3. What is the output with the statement System.out.println(x+y); if x and y are int values where x=10 and y=5?

a) 15

b) 105

c) 10 5

d) x+y

e) An error since neither x nor y is a String

4 (int) Math.random()* 10 + 15; What numbers will print?

a) 0 through 25

b) 15 through 25

c) 10 through 15

d) 15 through 24 9 + 15 = 24 start at 15 end at 24

5. Given the following assignment statement, which of the following answers is true regarding the order that the

operators will be applied based on operator precedence?

a = (b + c) * d / e – f;

a) *, /, +, -

b) *, +, /, -

c) +, *, /, -

d) +, /, *, -

e) +, -, *, /

6. when you create the method: public void upDateHours(double h) {

The parameter in this method is the

a) actual parameter

b) formal parameter

c) method parameter

d) content parameter

7. When you call the method: object.upDateHours(7.5)

The parameter in the method call to the upDateHours method is the

a) actual parameter

b) formal parameter

c) method parameter

d) content parameter

8 Which of the following would return the last character of the String x?

a) x.charAt(0);

b) x.charAt(last);

c) x.charAt(length(x));

d) x.charAt(x.length( )-1);

e) x.charAt(x.length( ));

9. What does the following program segment print? Hint: In nested for statements you finish the inner loop. . When repeated the inner loop starts over again.

for(f = 0; f < 3; f++)

for(g = 0; g < 2; g++)

System.out.print(f + ““ + g + ““ );

a) 000110112021 b) 010203111213

c) 01021112 d) 000102101112202122

10. What is the result of the operation 30 % 4?

a) 2 b) 3 c) 4 d) 7 e) 7.5

16. What will be printed by the following statement?

System.out.println(“Use a \”\\\””);

a) Use a \”\\\”

b) “Use a “\””;

c) Use a “\”

d) Use a \”\””

e) Use a “\\”

System.out.print(“Here we go! ”); print stay on line

System.out.println(“ 12345 ”); print and return

System.out.print(“ Test this if you are not sure. ”); print and stay on line

System.out.println(“ All done. ”); print and return

a) 1 b) 2 c) 3 d) 4

11. What output is produced by the following statement?

System.out.println(“50 plus 25 is “ + 50 + 25);

a) 50 plus 25 is 75 b) 50 plus 25 is 50 + 25

c) 50 plus 25 is 5025 d) “50 plus 25 is” 50 + 25

12. Consider the following variable declarations

int a = 5 int b = 4; double x = 5.0 double y = 4.0

Which of the following expressions have the value 1

I. (int) x / y

II. a/b

III.. a % b

a) II only

b) I and II only

c) I and III only

d) II and III only

e) I, II and III

13. What will be printed by the following code

boolean flag = true;

int x = -1

if(flag && (x > 0))

System.out.println(“yes”);

else if (x == 0)

System.out.println(“maybe”);

else if(!flag)

System.out.println(“sometimes”);

else

System.out.println(“no”);

a) yes

b) maybe

c) sometimes

d) no

e) There will be an error because you can’t mix integers and Booleans in the same expression.

14. In the following code, what value should go in the blank so that there will be exactly six lines of output?

for(int x = 0; x < ______; x = x + 2)

System.out.println(“x“);

a) 5 b) 6 c) 10 d) 11 e) 13

15. What output is produced by the following code fragment?

int limit = 100; int num1 = 15, int num2 = 40;

if(limit =2){ true

out.print("1"); print

if(a>=7) false

System.out.print("2"); skip

if(a ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download