wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

AP Comp

Total questions: 60

Worksheet time: 30mins

Name
Class
Date
1.

What is the output of the code: System.out.println(3+4+""+3-3);

a)

342

b)

345-3

c)

3

d)

72

e)

There is no output due to a compile error

2.

What is the output of the following code: System.out.println(3+4+""+5);

a)

345

b)

there is no output due to a compile error

c)

12

d)

39

e)

75

3.

Which of the following is a newline character?

a)

\b

b)

\n

c)

\t

d)

\r

4.

What of the following is not reserved for a java data type?

a)

char

b)

short

c)

double

d)

integer

e)

float

5.

What is the ASCII value of a '0'?

a)

97

b)

36

c)

48

d)

32

e)

65

6.

which of the following correctly defines a char variable?

a)

char c = a;

b)

char 'a';

c)

char = a;

d)

char c = 'a';

7.

Which of the following types uses the least memory?

a)

long

b)

float

c)

int

d)

char

e)

double

8.

What is output by the following code? System.out.println(3+4+""+5+5);

a)

710

b)

755

c)

340

d)

there is no output due to a compile error

9.

What is the output of the code below? System.out.println( "\"9" );

a)

99

b)

\"9

c)

"9

d)

\

10.

Which of the following types uses the most memory?

a)

short

b)

float

c)

double

d)

int

11.

Which of the lines correctly defines a double variable?

a)

d = 234.1

b)

double d = 234.1;

c)

double = 234.1;

12.

What is the output by the code below?

int num = 5; System.out.println("num");

a)

num

b)

5

c)

num 5

d)

num = 5

13.

Which of the following lines correctly defines a String variable?

a)

String = "cdef";

b)

String s = "cdef";

c)

String s = cdef

d)

String;

14.

What is the output of the code below? System.out.println(3+6);

a)

3

b)

0

c)

9

d)

6

15.

What is the ASCII value of a space?

a)

65

b)

97

c)

32

d)

46

16.

What is the output by the code below? double num = 3.5;

System.out.println("Number: "+num

a)

3.5

b)

There is no output due to a syntax error

c)

Number:

d)

Number: 3.5

17.

What is the output by the following code? System.out.println(3+4+""+5+3);

a)

715

b)

There is no output due to a compile error

c)

36

d)

12

18.

What is the ASCII value of 'B'?

a)

43

b)

97

c)

66

d)

65

19.

What is the output by the code below?

System.out.println(3+" "+3);

a)

3" "3

b)

6" "6

c)

3 3

d)

3

20.

Which of the following is the tab character?

a)

\t

b)

\nl

c)

\r

d)

\n

21.

Every method must have an open and close what?

a)

semicolon

b)

brace

c)

bracket

d)

period

22.

What is the output by the code below?

System.out.println("apl\tus");

a)

apl us

b)

apl\tus

c)

apltus

d)

aplus

23.

What is the output by the code below?

System.out.println("Hello ");

System.out.print("people ");

System.out.println("everywhere ");

a)

Hello people everywhere

b)

Hello

people everywhere

c)

Hello

people

everywhere

d)

Hello people

everywhere

24.

Which of the following methods would move the cursor down to the next line?

a)

prinT()

b)

printLINE()

c)

printLn()

d)

println()

25.

What is the output by the following code?

System.out.print("ap\\lus");

a)

us

b)

aplus

c)

apl\us

d)

ap\lus

26.

Which of the following is a valid identifier in java

a)

(abce

b)

java1234

c)

main

d)

123java

27.

What is the output by the code below?

String x = "Hello";

System.out.println("\String s");

a)

Hello

b)

There is no output due to a syntax error

c)

There is no output due to a runtime error

d)

String s

28.

What is the output by the following code?

String s = "aplus";

System.out.println(s);

a)

aplus

b)

aplu

c)

sulps

d)

s

29.

what is the output by the code below?

double y = 9.0;

int x = y;

System.out.println(x);

a)

There is no output due to a runtime error

b)

9

c)

9.0

d)

Syntax error

30.

What is the output by the code below?

int x = 3;

double y = x;

System.out.println(y);

a)

9

b)

Syntax error

c)

Runtime error

d)

3.0

31.

Which of the following can be used to comment code in java?

a)

//

b)

]*

c)

[*

d)

{*

32.

What is the output by the code below?

char c = 65;

System.out.println(c);

a)

A

b)

a

c)

65

d)

c

33.

What is the output of the code below?

System.out.println(""+3+4+5);

a)

29

b)

12

c)

compile error

d)

345

34.

Which of the following lines correctly defines an integer variable?

a)

int i = 234

b)

i = 234

c)

int i = 234;

d)

integer i = 234;

35.

Never put a semicolon before an open what?

a)

brace

b)

store

c)

bracket

d)

window

36.

What is the ASCII value of 'b'?

a)

98

b)

66

c)

43

d)

97

37.

Which of the following is a 32 bit data type?

a)

short

b)

char

c)

double

d)

int

38.

Which of the following would print one backslash on the screen if used in a print() or println()?

a)

\\

b)

/\

c)

\\\

d)

\b

39.

What is the output by the code below?

int cost = 2.65;

System.out.println("Price: "+cost);

a)

runtime error

b)

syntax error

c)

Price: 2.65

d)

2.65

40.

In java, every statement ends with what?

a)

;

b)

\

c)

]

d)

)

41.

What is output by the code below?


char x = 'A';

x--;

System.out.print(x + 3);

a)

C

b)

D

c)

67

d)

68

42.

What is output by the code below?


System.out.print(7 % 3);

a)

0.5

b)

1

c)

2

d)

3

43.

What is output by the code below?


System.out.println( 5 / 0);

a)

5

b)

0

c)

5.0

d)

There is no output due to a runtime error

44.

What is output by the code below?


double x = 5 / 3;

System.out.print(x);

a)

0

b)

1

c)

1.66

d)

1.0

45.

What is output by the code below?


System.out.print( (double) 4 / 2 );

a)

1

b)

1.0

c)

2.0

d)

2

46.

What is output by the code below?


System.out.print( 9 / 11 );

a)

0.8

b)

1

c)

2

d)

0

47.

What is output by the code below?


System.out.print(15.7 % 5);

a)

0.7

b)

0.3

c)

3

d)

0

48.

What is output by the code below?


System.out.print( (double)3 / 6 );

a)

0.5

b)

1

c)

2

d)

3

49.

What is output by the code below?


int x = 5, y = 6;

int z = x + y;

double a = z;

System.out.print(a);

a)

5

b)

6

c)

11

d)

11.0

50.

What is output by the code below?


int x = 25;

x = x % 5;

System.out.print(x);

a)

0

b)

1

c)

2

d)

3

51.

What is output by the code below?


System.out.println( Math.pow( Math.sqrt(16),3) );

a)

90.0

b)

64.0

c)

81.0

d)

91.0

e)

27.0

52.

What is output by the code below?


System.out.println( Math.abs( -9 ) );

a)

9.0

b)

-10

c)

-9

d)

10

e)

9

53.

What is output by the code below?


System.out.println( Math.pow(3,2) );

a)

6.0

b)

7.0

c)

8.0

d)

9.0

e)

27.0

54.

What is output by the code below?


System.out.println( Math.round( 10 / 4) );

a)

2

b)

3

c)

2.0

d)

3.0

e)

4

55.

What is output by the code below?


System.out.println( Math.ceil(7.1) );

a)

6.0

b)

7.0

c)

8.0

d)

9.0

e)

27.0

56.

What is output by the code below?


public class CS

{

public void one()

{

System.out.print("go");

}


public void two()

{

System.out.print("back");

}

}


//code in the main of another class

CS test = new CS();

test.one();

test.two();

test.two();

a)

go

b)

back

c)

goback

d)

gobackback

e)

gobackgobackgoback

57.

What is a method?

a)

a tool that helps organize a program

b)

a tool that complicates a program

c)

a tool that makes a program longer

d)

a tool that makes a program harder to read

e)

a tool that makes a program more disorganized

58.

What is output by the code below?


public class CS

{

public void one()

{

System.out.print("go");

}


public void two()

{

System.out.print("back");

}

}


//code in the main of another class

CS test = new CS();

test.two();

test.one();

test.two();

a)

go

b)

gobackgoback

c)

backgoback

d)

gobackback

e)

gobackgobackgo

59.

What is output by the code below?


public class CS

{

public void one()

{

System.out.print("fun");

}

}


//code in the main of another class

CS test = new CS();

test.one();

a)

fun

b)

funny

c)

funfun

d)

notfun

e)

sofun

60.

What is output by the code below?


public class CS

{

public void one()

{

System.out.print("fun");

}

}


//code in the main of another class

CS test = new CS();

test.one();

test.one();

test.one();

test.one();

a)

fun

b)

funny

c)

funfun

d)

notfun

e)

funfunfunfun