Log in
Sign up for FREE
arrow_back
Library
Semester Final AP Computer Science
By Mickey Arnold
star
star
star
star
star
Share
share
Last updated about 2 years ago
41 questions
Add this activity
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
Question 1
1.
Question 2
2.
Question 3
3.
Question 4
4.
Question 5
5.
Question 6
6.
Question 7
7.
Question 8
8.
Question 9
9.
Question 10
10.
Question 11
11.
Question 12
12.
Question 13
13.
Question 14
14.
Question 15
15.
Question 16
16.
Question 17
17.
Question 18
18.
Question 19
19.
Question 20
20.
Question 21
21.
Question 22
22.
Question 23
23.
Question 24
24.
Question 25
25.
Question 26
26.
Question 27
27.
Question 28
28.
Question 29
29.
Question 30
30.
Question 31
31.
Question 32
32.
Question 33
33.
Question 34
34.
Question 35
35.
Question 36
36.
Question 37
37.
Question 38
38.
Question 39
39.
Question 40
40.
Question 41
41.
What is output by the code below?
int x = 10 % 3;
System.out.print( x );
3
2
1
0
4
What is output by the code below?
int x = 10 / 3 ;
System.out.print( x );
1
2
4
3
0
What is output by the code below?
int x = 5 / 2;
System.out.print( x );
There is no output due to a syntax error.
2.5
3
2
1
What is output by the code below?
double x = (double)5 / 2;
System.out.print( x );
2.5
2
7
0
3
What is output by the code below?
System.out.print( 10 + 5 * 2);
10
17
100
30
20
What is output by the code below?
System.out.print("a\tc" );
atc
ac
a\tc
a\c
a c
What is output by the code below?
public static void main(String args[ ] )
{
}
main
there is no output
String
args
0
What is output by the code below?
String s = "123";
if(s.equals("123"))
out.println("true");
else
out.println("false");
false
321
true
123
error
What is output by the code below?
String s = "abcdef";
out.println( s );
adcd
abcde
s
abc
abcdef
In Java, every program statement ends with a what ?
;
}
\
[
{
What is output by the code below?
Scanner s = new Scanner("a b cd e");
String result = "";
while( s.hasNext() )
{
result = result + s.next();
}
out.println(result);
a
abce
ab
abcde
abcd
What is output by the code below?
int x = 0;
String w = "abcdefghixk";
for(x=w.length()-1; x>=0; x=x-2)
{
out.print(w.charAt(x));
}
kxihgfedcba
acegixk
abcdefghixk
fghij
kigeca
What is output by the code below?
for(int x=5; x < 20; x=x+3)
System.out.print(x + " ");
5 8 11 14 17
11 14 17 20
5 8 11 14 17 20 23
5 8 11 14 17 20
8 11 14 17 20
What is output by the code below?
int x = 66;
if ( x == 67 )
System.out.print("67" );
else
System.out.println("!67");
!67
66
false
true
67
What is output by the code below?
System.out.println( 3 + " " + 3 );
6 6
3" "3
3
3 3
6
What is output by the code below?
System.out.println( 3 + 6 );
6
12
9
3
0
What is the output?
System.out.println( "\"9" );
9
"9
None of these
\
\"9
Which of the following Scanner methods can be used to read in a int?
nextDouble()
nextFloat()
nextInt()
next()
nextByte()
Which of the following Scanner methods can be used to read in a double?
next()
nextInt()
nextByte()
nextDouble()
nextFloat()
Which of the following Scanner methods can be used to read in a String?
nextDouble()
next()
nextInt()
nextFloat()
nextByte()
What is output by the following code?
int total = 0;
for(int i=1; i <= 10; i=i+3)
for(int x=1; x <= i; x=x+2)
total = total + x;
out.println(total);
40
44
48
46
42
What is output by the code below?
int x=9;
do{
x--;
}while(x>5);
out.println(x);
7
3
5
6
4
What is output by the code below?
System.out.println( Math.sqrt(81) );
8.0
9.0
10.0
6.0
7.0
What is output by the code below?
System.out.println( Math.floor(6.7) );
7.0
10.0
8.0
9.0
6.0
What is output by the code below?
System.out.println( Math.ceil(6.7) );
8.0
9.0
6.0
10.0
7.0
What is output by the code below?
System.out.println( Math.pow(3,3) );
12.0
3.0
9.0
6.0
27.0
What is output by the code below?
String r = "abcdefghi";
out.println(r.charAt(3));
a
c
e
b
d
What is output by the code below?
int s=0, x=0;
while(s<=10)
{
x += s % 2;
s=s+1;
}
System.out.println( x );
3
2
4
6
5
What is output by the code below?
int t=1, amount=0;
do{
amount = amount + t;
t = t + 2;
}while(amount<20);
System.out.print(amount);
20
25
27
22
24
What is output by the code below?
String u = "abcdefghi";
out.println(u.substring(3,5));
def
efgh
cde
de
d
What is output by the code below?
String v = "abcdefghi";
out.println(v.indexOf(‘d’));
3
4
6
5
7
What is output by the code below?
String w = "abcdefghi";
out.println(w.indexOf(‘x’));
3
6
5
4
-1
What is output by the code below?
Scanner chop = new Scanner("1 2 3 4 5");
int x = 0;
while(chop.hasNextInt())
{
x += + chop.nextInt();
}
System.out.println( x );
6
9
15
10
3
What is output by the code below?
Scanner chopper = new Scanner("a b c d e");
out.print(chopper.next());
out.print(chopper.next());
out.print(chopper.next());
a b c
abcde
abc
a b c d e
abcd
What is output by the code below?
String r = "abcdefghi";
System.out.println(r.substring(3,r.length()));
there is no output due to a runtime error
efghi
cdefghi
bcdefghi
defghi
What is output by the code below?
String r = "racecar";
System.out.println(r.lastIndexOf('a'));
4
6
-1
5
1
Which of the following can appear anywhere in a variable name
I. numbers
II. underscores
III. money signs
IV. alphabetic characters
II and IV only
I, II, III, and IV
II, III, and IV only
III and IV only
IV only
What is output by the code below?
public static int go2(int i)
{
int sum = 0;
for(int j = 0;j<i;j++)
sum+=j*2+1;
return sum;
}
////////////////////////////////////////////////////////////////////////////////////
//client code in the main of a runner class
System.out.println(go2(6));
36
45
38
30
25
What is output by the code below?
int x = 3 % 10;
System.out.print( x );
2
4
1
3
0
What is output by the code below?
double x = 5 / 2;
System.out.print( x );
7
0
2.5
3
2.0
What is output by the code below?
System.out.print( 10 * 6 / 4);
10
20
15
30
17