Вы находитесь на странице: 1из 20

Larry Singleton 324

My Home Home FCBOE Student Achievement McIntosh HS

Edit Mode is: • ON ?


AP Computer Science A (4th & 5th Periods)
(Class has been unavailable to students since Monday, December 31, 2018) Tests
Preview Test: 2018 AP CS A Semester Exam

Preview Test:
Question 2018Status:
Completion AP CS A Semester Exam

Test Information
Description A Multiple Choice Exam with questions modeled after the AP Exam. Questions cover
the topics/concepts learned this 1st Semester.

Instructions Select the best answer for each question.

Multiple Not allowed. This test can only be taken once.


Attempts
Force This test can be saved and resumed later.
Completion

QUESTION 1 2 points   Save Answer

What is the output by the code below?


 
System.out.println( "\"99" );

a. 99"

b. \

c. 99

d. "99

e. \"9

QUESTION 2 2 points   Save Answer

What is output by the following code?


 
System.out.println(7 + "" + 5);

a. 12

b. 75

c. there is no output due to a compile error

d. 39
Click Save and Submit to save and submit. Click Save All Answers to save all answers.
e. 345
QUESTION 3 2 points   Save Answer

In Java, every program statement ends with a what


a. {

b. \

c. }
Question
d. ;Completion Status:

e. (

QUESTION 4 2 points   Save Answer

Which of the following lines correctly defines a String


variable?
a. String s = "aplus";
b. String;

c. String s = aplus;
d. String = "aplus";
e. s = "aplus";

QUESTION 5 2 points   Save Answer

Which of the following lines correctly defines a double


variable?
a. double v = 9.1
b. double = 9.1
c. double v = 9.1;
d. double = 9.3;
e. v = 9.1

QUESTION 6 2 points   Save Answer

Which of the following Scanner methods can be used to read in the


value 11.25

a. nextDouble()

b. nextLong()

c. nextByte()
d. nextInt()

e. A and B only

Click Save and Submit to save and submit. Click Save All Answers to save all answers.
QUESTION 7 2 points   Save Answer

What is output by the code below?


 
public class CS
{
public void one()
{
System.out.print("fun");
}
}
Question
  Completion Status:
//code in the main of another class
CS test = new CS();
test.one();
test.one();
test.one();
test.one();

a. fun

b. funny

c. funfunfunfun

d. funfun

e. notfun

QUESTION 8 2 points   Save Answer

What is output by the code below?


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

a. 3

b. 1

c. 2

d. 0

e. 0.5

QUESTION 9 2 points   Save Answer

What is output by the code below?


 
System.out.print(7 % 3);

a. 3

b. 0

c. 1

d. 2

e. .5

Click Save and Submit to save and submit. Click Save All Answers to save all answers.
QUESTION 10 2 points   Save Answer

What is output by the code below?


 
int x = 5, y = 6;
int z = x + y;
double a = z;
System.out.print(a);

a. 17

Question
b. 6Completion Status:

c. 11.0

d. 5

e. 11

QUESTION 11 2 points   Save Answer

How many constructors are there in class It?


 
public class It
{
private int val;

public It()
{
val = 7;
}
 
public int getIt()
{
return val;
}
 
public String toString()
{
return "" + getIt();
}
}

a. 0

b. 1

c. 2

d. 3

e. 4

QUESTION 12 2 points   Save Answer

How many instance variables are there in class It?


 
public class It
{
private int val;
Click Save and Submit to save and submit. Click Save All Answers to save all answers.

public It()
{
val = 8;
}
 
public String toString()
{
return "" + val;
}
}

a. 0
Question Completion Status:
b. 1

c. 2

d. 3

e. 4

QUESTION 13 2 points   Save Answer

What is output by the code below?


 
public class Check
{
private int one, two, total;
 
public void setNums(int n1, int n2)
{
one = n1;
two = n2;
}
 
public void add()
{
total = one + two;
two = 5;
}
 
public String toString()
{
total = 2;
return "" + total;
}
}
 
//code in the main of another class
Check test = new Check();
test.setNums(-6,3);
test.add();
out.println(test);

a. 5

b. 4

c. 2

d. -3

e. -1and Submit to save and submit. Click Save All Answers to save all answers.
Click Save
QUESTION 14 2 points   Save Answer

What is output by the code below?


 
System.out.println(
Math.max(Math.min(9,5),11) );

a. 9
Question
b. 0Completion Status:

c. 14

d. 11

e. 16

QUESTION 15 2 points   Save Answer

What is output by the code below?


 
System.out.println( Math.floor(5.7) );

a. 7.0

b. 6.0

c. 5.0

d. 27.0

e. 8.0

QUESTION 16 2 points   Save Answer

What is output by the code below?


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

a. 2

b. 2.5

c. 3,0

d. 2,0

e. 3

QUESTION 17 2 points   Save Answer

Consider the following code segment.


 
String s = "dogfood";
System.out.println( s.length() );

Click Save and Submit to save and submit. Click Save All Answers to save all answers.
a. 5

b 6
b. 6

c. 4

d. 3

e. 7

QUESTION 18 2 points   Save Answer

Consider the following code segment.


 
Question Completion Status:
String s = "dogfood";
System.out.println( s.substring(4) );

a. dogf

b. food

c. dogs

d. ood

e. dog

QUESTION 19 2 points   Save Answer

What is returned by the call go(-3) ?


 
public static String go( int a )
{
if(a>=0)
{
if(a>=1)
return "1";
return "2";
}
return "3";
}

a. 1

b. 2

c. 3

d. 12

e. 23

QUESTION 20 2 points   Save Answer

What is the output?


 
int a = 40;
if(a>=20)
out.print("1");
if(a>=50)
out.print("2");
out.print("3");
Click Save and Submit to save and submit. Click Save All Answers to save all answers.

a 23
a. 23

b. 13

c. 12

d. 123

e. 3

QUESTION 21 2 points   Save Answer

Question Completion Status:


What is returned by the call go(50,50)?
 
public static String go(int x, int z)
{
String s = "";
if(x >= 50)
if(z > 55)
s += "def";
s += "fun";
return s;
}

a. de un

b. fun

c. 50

d. fundef

e. def

QUESTION 22 2 points   Save Answer

What values will be stored in a and b after execution of the following


program segment?
 
int a = 7, b = 11;
if(a<b){
if(a < 20)
a *= 2;
else
a = b-a;
b = b/3;
}
else {
if(b < 15)
b = b*2+3;
else
b = a-b+15;
a = a/4;
}

a. a = 16 b = 4
b. a = 12 b = 3
c. a = 18 b = 5
d. a = 10 b = 7
Click Save and Submit to save and submit. Click Save All Answers to save all answers.
e. a = 14 b = 3
QUESTION 23 2 points   Save Answer

What is output by the code below?


 
int p = 40;
if(p >= 20)
{
out.print("1");
if(p >= 30)
out.print("2");
Question Completion Status:
}
else
out.print("3");

a. 1

b. 123

c. 3

d. 12

e. 13

QUESTION 24 2 points   Save Answer

What is output by the code below?


 
int a = 105, b = 40;
if( a > 90)
if( b > 100)
out.print("go");
else if( b > 90)
out.print("it");
else
out.print("up");
out.print("on");

a. on

b. upon

c. iton

d. goon

e. itupon

QUESTION 25 2 points   Save Answer

What is output by the code below?


 
int ans = 0;
for(int i=0; i<20; i=i+3)
if( i % 2 == 0 )
ans += i;
System.out.print( ans );

Click Save
a. 20and Submit to save and submit. Click Save All Answers to save all answers.

b 25
b. 25

c. 30

d. 27

e. 36

QUESTION 26 2 points   Save Answer

What is returned by the call go( 7 ) ?


Question
  Completion Status:
public static String go( int x)
{
String s = "";
for(int n = x; n > 0; n = n - 2)
s = s + n + " ";
return s;
}

a. 7 5 3 1

b. 7 5 3

c. 7 5

d. 1

e. 7

QUESTION 27 2 points   Save Answer

What is output by the code below?


 
for(int i=5; i<20; i=i+3)
out.print(i);

a. 581114172023

b. 58111417

c. 8111417
d. 5811141720

e. 581114

QUESTION 28 2 points   Save Answer

What is output by the code below?


 
int j=3, ans=0;
while(j<7){
ans+=j;
j++;
}
System.out.print( ans );

a. 22
Click Save and Submit to save and submit. Click Save All Answers to save all answers.
b. 19
c. 20

d. 18

e. 16

QUESTION 29 2 points   Save Answer

What is output by the code below?


 
int j=1;
Question Completion Status:
while(j<8)
{
j++;
System.out.print( j );
}

a. 345678

b. 8

c. 2345678
d. 234567

e. 23456789

QUESTION 30 2 points   Save Answer

What is output by the code below?


 
int n=23, z=0;
while( n > 16 )
{
z = z + n;
n-=4;
}
System.out.print( z );

a. 45

b. 41

c. 42

d. 46

e. 44

QUESTION 31 2 points   Save Answer

What is output by the code below?


 
int c = 11;
if( c>3 && c>10 )
System.out.print("it");
System.out.print("up");

a. it
Click Save and Submit to save and submit. Click Save All Answers to save all answers.
b. up
c. upit
d.

itup

e. upup

QUESTION 32 2 points   Save Answer

What is output by the code below?


 
Question Completion Status:
boolean a=true;
boolean b=false;
out.println( a &&( a || b ));

a. false

b. 0

c. 1

d. true

e. true or false

QUESTION 33 2 points   Save Answer

What is output by the code below?


 
int e=-4;
if(!(e>0))
System.out.print("fun");
System.out.print("go");

a. go

b. fun

c. gofun

d. fungo

e. there is no output

QUESTION 34 2 points   Save Answer

What is output by the code below?


 
String s = "at";
for(int x=0; x<s.length(); x++)
{
for(int k=0;k<=x;k++){
System.out.print(s.charAt(x));
}
}

a. atat

b. aatt
Click Save and Submit to save and submit. Click Save All Answers to save all answers.
c. tta

d. at
d. at

e. att

QUESTION 35 2 points   Save Answer

What is output by the code below?


 
int total = 0;
for(int i = 1; i <= 10; i = i + 3)
for(int
Question CompletionxStatus:
= 1; x <= i; x = x + 3)
total = total + x;
System.out.println(total);

a. 40

b. 42

c. 44

d. 46

e. 48

QUESTION 36 2 points   Save Answer

What is output by the code below?


 
int[] array = {5,7,8,11,4};
for(int i=0; i<array.length/2; i=i+2)
{
array[i]=array[array.length-i-1];
}
System.out.println(array[0]);

a. 7

b. 5

c. 8

d. 4

e. 11

QUESTION 37 2 points   Save Answer

What is output by the code below?


 
int[] nums = new int[10];
for (int i=0; i < nums.length; i++)
{
nums[i] = i*2;
}
System.out.println(nums[5]);

a. 10

b. 12
Click Save and Submit to save and submit. Click Save All Answers to save all answers.
c. 14
d. 16

e. 18

QUESTION 38 2 points   Save Answer

What is output by the code below?


 
int[] array = {5,7,8,11,4};
out.println(array.length);
Question Completion Status:

a. 2

b. 1

c. 4

d. 5

e. 3

QUESTION 39 2 points   Save Answer

What is output by the code below?


 
List<Integer> list = new ArrayList<Integer>
();
list.add(8);
list.add(5);
list.add(6);
list.remove(0);
System.out.println(list);

a. [5, 6, 8]
b. [8, 5]
c. [8, 6]
d. [5, 6]
e. [8, 5, 6]

QUESTION 40 2 points   Save Answer

What is output by the code below?


 
List<String> list = new ArrayList<String>
();
list.add("it");
list.add("by");
list.set(0,"up");
list.add(1,"at");
list.set(2,"go");
list.add("to");
System.out.println(list);

a. [up, at, go, to]


Click Save and Submit to save and submit. Click Save All Answers to save all answers.
b. [go, by, at, it]

c [up by at go]
c. [up, by, at, go]
d. [go, up, by, to]
e. [up, at, go, it]

QUESTION 41 2 points   Save Answer

What is output by the code below?


 
List<Integer> list = new ArrayList<Integer>
Question Completion Status:
();
list.add(8);
list.add(2);
list.add(5);
list.set(0, 11);
list.add(6);
list.add(0,9);
list.set(1, -5);
list.remove(1);
System.out.println(list);

a. [-5, 6, 9, 8]
b. [9, 2, 5, 6]
c. [2, 5, 6, 9]
d. [-5, 6, 11, 2]
e. [9, 2, 6, 5]

QUESTION 42 2 points   Save Answer

What is output by the code below?


 
int[] x = new int[3];
x[0] = 5;
out.println( x[0] );

a. 3

b. 10

c. 5

d. 0

e. 8

QUESTION 43 2 points   Save Answer

What is output by the code below?


 
String[] x;
x = new String[7];
x[1] = "go";
x[4] = "up";
x[2] = "by";
System.out.println(
Click Save and Submit to save and x[0]
submit. );
Click Save All Answers to save all answers.
a. at
b.

by

c. null

d. up

e. go

Question Completion
QUESTION 44 Status: 2 points   Save Answer

Consider the following class definitions.


 
public class Cat
{
private String name:
private int age;
 
public Cat( String n, int a )
//implementation not shown
 
public String getName()
//implementation not shown
 
public int getAge()
//implementation not shown
 
//other methods not shown
}
 
//client code in another class
Cat[] bunch = new Cat[5];
bunch[0] = new Cat("rocket", 8);
bunch[3] = new Cat("sam", 15);
bunch[4] = bunch[3];
bunch[3] = bunch[0];
System.out.println( bunch[4].getAge() );

a. 3

b. 8

c. 12

d. 15

e. null

QUESTION 45 2 points   Save Answer

How many constructors are there in class It?


 
public class It
{
private int val;

public It()
{
Click Save and Submit to save and submit. Click Save All Answers to save all answers.
val = 7;
}
 
public int getIt()
{
return val;
}
 
public String toString()
{
return "" + getIt();
}
}
Question Completion Status:

a. 0

b. 1

c. 2

d. 3

e. 4

QUESTION 46 2 points   Save Answer

What is output by the code below?


 
public class Check
{
private int fun;
 
public void change()
{
fun = 5;
int fun = 6;
}
 
public String toString()
{
return "" + fun;
}
}
 
//client code
Check test = new Check();
test.change();
out.println(test);

a. There is no output due to a syntax error.

b. 5

c. 7

d. 6

e. 0

QUESTION 47 2 points   Save Answer

How many
Clickmethods
Save andare there
Submit toin class
save andIt?
submit. Click Save All Answers to save all answers.
 
public class It
public class It
{
private int val;

public It()
{
val = 7;
}
 
public int getIt()
{
return val;
}
Question Completion Status:
 
public String toString()
{
return "" + getIt();
}
}

a. 2

b. 0

c. 1

d. 3

e. 4

QUESTION 48 2 points   Save Answer

Consider the following Pig class and client code below.


 
class Pig
{
public Pig( int x, String y )
{
//code not shown
}
}
 
// client code found in PigRunner.java
ArrayList< Pig > list;
list = new ArrayList< Pig >();
 
// several Pigs have been added to the list
 
< *1 >
 
Which of the following could fill < *1 > to print out each Pig
in the list on a seperate line ?
 
I.
for( Pig it : list )
System.out.println( list );
 
II.
for( Pig it : list )
System.out.println( list.get( it ) );
  Save and Submit to save and submit. Click Save All Answers to save all answers.
Click
III.
for( Pig it : list )
for( Pig it : list )
System.out.println( it );

a. I only
b. II only
c. III only
d. I and II only
e. I and III only

Question Completion Status:

QUESTION 49 2 points   Save Answer

What is output by the code below?


 
ArrayList<String> list = new
ArrayList<String>();
list.add("one");
list.set(0, "two");
list.add(0, "three");
System.out.println(list);

a. [one]

b. one,two, three
c. [three, two, one]
d. [two, three]
e. [three, two]

QUESTION 50 2 points   Save Answer

All variables located inside of an interface are automatically


labeled with which of the following modifiers?
a. static

b. abstract

c. nal

d. A & C only

e. A, B, & C

QUESTION 51 2 points   Save Answer

Consider the classes and client code below to determine what is printed
by the client code.
 
public class N
{
private int one;
public N(){
one=5;
}
public String toString(){
Click Save and Submit to save and submit. Click Save All Answers to save all answers.
return ""+ one;
}
}
 

public class O extends N


{
}
 
//client code
N it = new O();
System.out.println( it );

a. O
Question Completion Status:
b. 5

c. 0

d. null

e. N

QUESTION 52 2 points   Save Answer

Which reserved word is used to indicate that one class is a


child or descendant of another class?
a. extends

b. child

c. implements

d. derives

e. super

QUESTION 53 2 points   Save Answer

Which of the following could be placed in Demo?


 
public abstract class Demo
{
}

a. public abstract void fun() { }


b. protected abstract void fun();
c. void fun();
d. public void fun() { }
e. A,B, and C

Click Save and Submit to save and submit. Click Save All Answers to save all answers.

Вам также может понравиться