Log in
Sign up for FREE
arrow_back
Library

Semester Final Review

star
star
star
star
star
Last updated about 2 years ago
130 questions
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
1
1
1
1
1
1
1
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
2.5
8.75
8.75
8.75
8.75
8.75
8.75
8.75
8.75
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.

Question 42
42.

Question 43
43.

Question 44
44.

Question 45
45.

Question 46
46.

Question 47
47.

Question 48
48.

What is output by the code below?

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

Question 49
49.

What is output by the code below?

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

Question 50
50.

What is output by the code below?
System.out.println( Math.pow(6,2) );

Question 51
51.

What is output by the code below?

System.out.println( (int)Math.pow( Math.sqrt(60),2) );

Question 52
52.

What is output by the code below?
System.out.println( Math.pow( Math.sqrt(25),2) );

Question 53
53.

What is output by the code below?
System.out.println( Math.floor(6.7) );

Question 54
54.

What is output by the code below?
System.out.println( Math.max(26,18) );

Question 55
55.

What is output by the code below?
System.out.println( Math.min(36,8) );

Question 56
56.

What is output by the code below?
System.out.println( Math.sqrt(64) );

Question 57
57.

What is output by the code below?
public class Fun
{
public int times(int num1, int num2)
{
return num1 * num2;
}
}
Fun aplus = new Fun();
System.out.println( aplus.times( 8, 6 ) );

Question 58
58.

What is output by the code below?
public class Fun
{
public int times(int num1, int num2)
{
return num1 + num2;
}
}
Fun aplus = new Fun();
System.out.println( aplus.times( 23, 13 ) );

Question 59
59.

What is output by the code below?
public class Fun2
{
public static int times(int num1, int num2)
{
return num1 * num2;
}
}
System.out.println( Fun2.times(6 , 7) );

Question 60
60.

What is output by the code below?
public class Fun2
{
public static int times(int num1, int num2)
{
return num1 + num2;
}
}
System.out.println( Fun2.times(5 , 5) );

Question 61
61.

How many methods does Bird contain?
public class Bird
{
public void speak()
{
out.println("chirp-chirp");
}
public void sayName()
{
out.println("baby bird");
}
}

Question 62
62.

How many return methods does Bird contain?
public class Bird
{
public void speak()
{
out.println("chirp-chirp");
}
public void sayName()
{
out.println("baby bird");
}
}

Question 63
63.

What is output by the code below?
public class Test
{
public void go()
{
out.print("A");
}
public void fun()
{
out.print("B");
}
}
Test x = new Test();
x.go();

Question 64
64.

What is output by the code below?
public class Test
{
public void go()
{
out.print("A");
}
public void fun()
{
out.print("B");
}
}
Test x = new Test();
x.go();
x.go();
x.go();

Question 65
65.

What is output by the code below?
public class Test
{
public void go()
{
out.print("A");
fun();
}
public void fun()
{
out.print("B");
}
}
Test x = new Test();
x.fun();
x.go();

Question 66
66.

What is output by the code below?
public class Test
{
public void go()
{
out.print("A");
}
public void fun()
{
out.print("B");
go();
}
}
Test x = new Test();
x.go();
x.fun();
x.fun();

Question 67
67.

Question 68
68.

Question 69
69.

Question 70
70.

Question 71
71.

Question 72
72.

Question 73
73.

Question 74
74.

Question 75
75.

Question 76
76.

Question 77
77.

Question 78
78.

Question 79
79.

Question 80
80.

Question 81
81.

Question 82
82.

Question 83
83.

Question 84
84.

Question 85
85.

Question 86
86.

Question 87
87.

Question 88
88.

Question 89
89.

Question 90
90.

Question 91
91.

Question 92
92.

Question 93
93.

Question 94
94.

Question 95
95.

Question 96
96.

Question 97
97.

Question 98
98.

Question 99
99.

Question 100
100.

Question 101
101.

Question 102
102.

Question 103
103.

Question 104
104.

Question 105
105.

Question 106
106.

Question 107
107.

Question 108
108.

Question 109
109.

Question 110
110.

Question 111
111.

Question 112
112.

Question 113
113.

Question 114
114.

Question 115
115.

Question 116
116.

Question 117
117.

Question 118
118.

Question 119
119.

Question 120
120.

Question 121
121.

Question 122
122.

Question 123
123.

Question 124
124.

Question 125
125.

Question 126
126.

Question 127
127.

Question 128
128.

int tot = 0;
for( int i=2; i<17; i++ ) {
tot = tot + i;
}
out.println( tot );

Question 129
129.

int count=0;
for(int j=4; j<23; j++) {
if(j%2==1)
count++;
}
out.println( count );

Question 130
130.

int sum=0;
for(int m=5; m<18; m++) {
if(m%2!=1)
sum=sum+m;
}
out.println(sum);

What is the output by the code below?
System.out.println( 3 + " " + 3 );
3" "3
6
6 6
3 3
3
What is the ASCII value of a space?
32
36
48
97
65
Which of the following would print one backslash on the screen if used in a print( ) or println( )?
\b
\\
\
\\\
/\
What is output by the following code?
System.out.println(""+3+4+5);
75
345
12
39
there is no output due to a compile error
What is the output by the code below?
System.out.println("Hello ");
System.out.print("people ");
System.out.println("everywhere ");
Hello
people everywhere
Hello people everywhere
Hello
people
everywhere
Hellopeopleeverywhere
What is output by the following code?
System.out.println(3+4+""+5*3);
36
757575
715
12
there is no output due to a compile error
What is the output by the code below?
int num = 5;
System.out.println("num");
num
num = 5
num 5
5
num: 5
What is the output by the code below?
System.out.println( "\"9" );
\
"9
99
9
\"9
What is the output by the code below?
char c = 65;
System.out.println(c);
0
65
c
a
A
Which of the following lines correctly defines a char variable?
char = a;
char c = ‘a’;
char ‘a’;
char c = a;
char = ‘a’;
Which of the following can be used to comment code in Java?
//
(
{*
[
}*
Which of the following is the tab character?
\t
\nl
\b
\n
\r
Which of the following lines correctly defines a String variable?
String s = cdef;
String s = "cdef";
s = "cdef";
String = "cdef";
String;
What of the following is not a legal reserved word for a java data type?
float
integer
char
short
double
What is the output by the code below?
int cost = 2.65;
System.out.println("Price: " + cost);
2.65
There is no output due to a error.
Price:
Price: 2.65
What is the output by the code below?
String s = "aplus";
System.out.println( s );
sulpa
s
aplus
plus
aplu
In Java, every program statement ends with a what ?
\
}
(
{
;
Every method must have an open and close what?
brace
chickens
bracket
period
semicolon
What is the output by the code below?
System.out.print( "ap\\lus" );
aplus
us
ap\lus
apl
apl\us
Which of the following is a 32 bit data type?
short
int
char
long
double
Which of the following Scanner methods can be used to read in 65535 ?
a. nextShort()
b. nextInt()
c. nextByte()
d. A and B only
e. A, B, and C
Which of the following Scanner methods can be used to read in a line of words?
nextInt()
nextShort()
nextLine()
nextFloat()
nextLong()
Which of the following Scanner methods can be used to read in the value “apluscompsciisthebest” ?
a. next()
b. nextDouble()
c. nextByte()
d. nextInt()
e. A and B only
Given the following statement, var must be defined as which of the following types?
var=keyboard.nextFloat();
float
byte
char
boolean
String
Given the following statement, var must be defined as which of the following types?
var=keyboard.nextLine();
float
byte
char
boolean
String
Which of the following Scanner methods can be used to read in a double?
a. nextInt()
b. nextDouble()
c. nextDble()
d. A and B only
e. A, B, and C
Given the following statement, var must be defined as which of the following types?
var=keyboard.nextLong();
short
byte
int
long
String
Which of the following Scanner methods can be used to read in a short?
nextByte()
nextShort()
nextshort()
nextShorts()
nextChar()
Which of the following is the Java class used for input?
a. Keyboard
b. Scanner
c. Reader
d. GetStuff
e. A and B only
Which of the following is used in the Scanner constructor to connect to the keyboard?
a. System.out
b. System.in
c. Keyboard.in
d. Keyboard.out
e. A and B only
Which of the following Scanner methods can be used to read in a String?
a. nextInt()
b. nextDouble()
c. next()
d. nextFloat()
e. nextByte()
Which of the following Scanner methods can be used to read in an integer?
a. nextInt()
b. nextDouble()
c. nextInteger()
d. A and B only
e. A, B, and C
Which of the following Scanner methods can be used to read in a byte?
nextInteger()
nextBite()
nextBite()
nextBite()
nextByte()
Which of the following Scanner methods can be used to read in the value
”apluscompsci is the best” ?
a. next()
b. nextLine()
c. nextByte()
d. nextInt()
e. A and B only
Which of the following would correctly define and instantiate a Scanner?
Scanner kb = Scanner(System.in);
Scanner kb = new Scanner(System.in);
Scanner new kb = Scanner(System.in);
Scanner kb = new kb(System.in);
none of these
Which of the following Scanner methods can be used to read in a long?
nextInt()
nextShort()
nextLine()
nextFloat()
nextLong()
Given the following statement, var must be defined as which of the following types?
var=keyboard.next();
float
byte
char
boolean
String
Which of the following Scanner methods can be used to read in 511.278 ?
a. nextDouble()
b. nextLong()
c. nextByte()
d. nextInt()
e. A and B only
Given the following statement, var must be defined as which of the following types?
var=keyboard.nextByte();
bytes
byte
bite
boolean
String
Given the following statement, var must be defined as which of the following types?
var=keyboard.nextDouble();
short
double
int
long
String
What is output by the code below?
double x = .5 + .5;
System.out.print(x);
0
1
0.0
1.0
2
What is output by the code below?
int x = 1;
x *= 5;
System.out.print(x);
0
1
2
3
5
What is output by the code below?
System.out.print( 4 - 3 );
-1
1
4
0
3
What is output by the code below?
System.out.print(4 % 3);
.5
1
2
0
3
What is output by the code below?
System.out.print( (int)9.6 );
10
6
9.0
9.6
9
What is output by the code below?
int x = 12,
y = 20;
int z = x + y;
double a = z;
System.out.print(a);
32.0
50
42
17.0
32
What is output by the code below?
System.out.println( 7 / 0);
0
7
0.7
27
There is no output due to a runtime error.
What is output by the code below?
public class Test
{
public void go()
{
out.print("A");
stop();
}
public void fun()
{
out.print("B");
go();
}
public void stop()
{
out.print("C");
}
}
Test x = new Test();
x.fun();
What is output by the code below?

String s = "apluscompsci";
System.out.println( s.substring(4,5) );
l
p
a
s
u
What is output by the code below?

String s = "apluscompsci";
System.out.println( s.substring( s.length()-1 ) );
i
s
a
p
ci
What is output by the code below?

String s = "apluscompsci";
System.out.println( s.charAt( s.length()-3 ) );
i
c
p
s
a
What is output by the code below?

String s = "apluscompsci";
System.out.println( s.charAt(0) );
p
a
c
i
s
What is output by the code below?

String s = "apluscompsci";
System.out.println( s.charAt(5) );
p
i
u
s
c
What is output by the code below?

String s = "apluscompsci";
System.out.println( s.indexOf( "s" ) );
9
5
4
6
3
What is output by the code below?

String s = "apluscompsci";
System.out.println( s.indexOf( "apluscomp" ) );
0
1
2
3
4
What is output by the code below?

String s = "ishouldofstudied";
System.out.println( s.length() );
12
13
16
15
14
What is output by the code below?

String s = "apluscompsci";
System.out.println( s.substring( 6 ) );
aplus
compsci
sci
o
ompsci
What is output by the code below?

String s = "apluscompsci";
System.out.println( s.indexOf( "b" ) );
0
1
2
3
-1
What is output by the code below?

String s = "apluscompsci";
int x = s.indexOf( "c" );
System.out.println( s.substring( x ) );
compsci
sci
comp
aplus
pluscompsci
What is output by the code below?

int x = "alligator".length() - "crocodile".length();
System.out.println( x );
-1
2
0
1
-2
What is output by the code below?

int x = "crocodile".length() - "croc".length();
System.out.println( x );
-1
-5
0
1
5
What is output by the code below?

String s = "apluscompsci";
System.out.println( s.substring(0,2) );
a
ap
p
us
pl
What is output by the code below?

String s = "apluscompsci";
int x = 3;
System.out.println( s.substring(x,x+1) );
m
0
p
u
s
What is output by the code below?

String s = "dog";
String r = "dog ";
System.out.println( s.equals( r ) );
null
1
false
0
true
What is output by the code below?

String s = "dog ";
String r = new String("dog");
System.out.println( s.equals( r ) );
1
0
false
true
null
What is output by the code below?

String s = "dog";
String r = new String("dog");
System.out.println( s != r );
1
false
0
true
null
What is output by the code below?

String s = "dog";
String r = "dog";
r = s;
s = null;
System.out.println( r );
false
dog
null
true
s
What is output by the code below?

String s = "dog";
String r = s;
s = null;
System.out.println( s );
true
null
dog
s
false
What is output by the code below?

String s = "Big dog";
String r = "A dog";
System.out.println( s.compareTo(r) );
0
false
true
1
null
What is output by the code below?

String s = "dog";
String r = "cog";
System.out.println( r.compareTo(s) );
-1
3
null
0
1
What is output by the code below?

String s = "dodge";
String r = "cloths";
System.out.println( s.compareTo(r) );
null
3
1
-1
0
What is output by the code below?

String s = "bob";
String r = "bod";
System.out.println( s.compareTo(r) );
-5
1
-2
6
-6
What is output by the code below?

String s = 12;
int x = Integer.parseInt( s );
System.out.println( x + 3 );
12
x3
There is no output due to an error.
0
15
What is output by the code below?

String s = "12.7";
Double x = Double.parseDouble( s );
System.out.println( x + 3 );
There is no output due to an error.
x3
15.7
12.7
0
What is output by the code below?

String s = "12.7";
double x = Double.parseDouble( s );
System.out.println( x + 3 );
12.7
15.7
0
x3
There is no output due to an error.
What is output by the code below?

String s = "12";
int x = Integer.parseInt( s );
System.out.println( s + x + 3 );
12123
12x3
27
There is no output due to an error.
1215
What is output by the code below?

System.out.println( "12" + 9 + 3 );
null
1212
There is no output due to an error.
24
1293
What is returned by the call myst("aplus","aplus")?
public boolean myst(String a, String b)
{
return a.equals( b );
}
true
null
1
0
false
What is returned by the call myst("aplus","aplus")?
public boolean myst(String a, String b)
{
return a == b;
}
0
1
null
false
true
What is returned by the call myst("ana","banana")?
public boolean myst(String a, String b)
{
return b.lastIndexOf(a)!=b.indexOf(a);
}
0
false
1
null
true
What is the purpose of myst?
public boolean myst(String a, String b)
{
return b.lastIndexOf(a)!=b.indexOf(a);
}
to determine if there are at least two occurrences of a in b.
none of the above
to determine if a occurs exactly once in b
to determine if there are less than two occurrences of a in b
to determine if a is in b
What is returned by the call go(60,78)?
public static String go(int x, int z)
{
String s = "xyz";
if(z > 60)
{
s += "def";
}
if(x <= 60)
s += "ghi";
return s;
}
def
xyzghi
ghi
xyz
xyzdefghi
Consider the following code segment.

String s = "red ball";
if(s.indexOf("a")>0)
s = s + " zed";
if(s.indexOf("z")>0)
s = "alpha " + s;
out.println(s);

What will be printed as a result of executing the code segment?
red ball
zed
alpha red ball zed
red ball zed
alpha
Consider the following code segment.

String s = "abac-adae-bfbg-bhbi";
int index = s.indexOf("b");
if(index > 0)
out.println(s.substring(index));

What will be printed as a result of executing the code segment?
there is no output
bac-adae-bfbg-bhbi
-bfbg-bhbi
bfbg-bhbi
bhbi
What is returned by the call go(7) ?
public static int go( int a )
{
int ans = 0;
if(a>=7)
{
ans += 1;
}
ans += 2;
return ans;
}
2
5
6
1
3
What is output by the code below?
String a = "1";
String b = new String("1");
if( a == b )
{
System.out.print( "up" );
}
if( a.equals(b) )
{
System.out.print( "on" );
}
System.out.print( "at" );
upon
uponat
onat
upat
There is no output due to an error.
Consider the following code segment.
double x = 19.8;
int y = 0;
if( x > 5 )
y += 5;
if( x > 10 )
y += 10;
if( x > 15 )
y += 15;
out.print( y );
What will be printed as a result of executing the code segment?
10
15
0
5
30
Consider the following code segment.
String s = "even";
if(s.indexOf("a")>0)
s = s + " zed";
if(s.indexOf("v")>0)
s = "alpha " + s;
out.println(s);
What will be printed as a result of executing the code segment?
alpha
zed
alpha even
even zed
even
Consider the following code segment.
String s = "apple";
if(s.indexOf("a")>0)
s = s + " zed";
if(s.indexOf("l")>0)
s = "alpha " + s;
out.println(s);
alpha apple
zed
alpha
apple
alpha apple zed
What is output by the code below?
int b = 100;
if( b > 100)
out.print("go");
else if( b > 90)
out.print("it");
else
out.print("up");
out.print("on");
on
upon
iton
goon
itupon
What is output by the code below?
int a = 75, b = 100;
if( a > 90)
if( b > 100)
out.print("go");
else if( b > 90)
out.print("it");
else
out.print("up");
out.print("on");
iton
itupon
on
upon
goon
What is output by the code below?
int a = 105, b = 120;
if( a > 90)
if( b > 100)
out.print("go");
else if( b > 90)
out.print("it");
else
out.print("up");
out.print("on");
upon
itupon
iton
goon
on
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");
goon
iton
itupon
on
upon
What values will be stored in c and d after execution of the following program segment?
int c = 5, d = 10;
if(d>c){
if(c > 50)
c /= 2;
else
c = d-c;
d = d/5;
}
else{
c = c/2;
d = d/2+3;
}
c = 6 d = 2
c = 6 d = 1
c = 5 d = 2
c = 7 d = 1
c = 6 d = 5
What values will be stored in c and d after execution of the following program segment?
int c = 12, d = 3;
if(d>c){
if(c > 50)
c /= 2;
else
c = d-c;
d = d/5;
}
else{
c = c/2;
d = d/2+3;
}
c = 13 d = 3
c = 6 d = 3
c = 9 d = 5
c = 6 d = 4
c = 7 d = 3
What is output by the code below?

int j = 11/2;
switch(j)
{
case 5:j++;break;
case 6:j++;break;
case 7:j++;break;
}
System.out.println(j);
7
5
6
0
8
What is output by the code below?
int x= 11;
switch( x )
{
case 11 : System.out.print("it");
case 21 : System.out.print("go");
case 98 : System.out.print("up"); break;
}
itgo
itgoup
goup
it
go
What is output by the code below?

int b = 110;
if( b > 100)
out.print("go");
else if( b > 90)
out.print("it");
else
out.print("up");
out.print("on");
goon
iton
itupon
on
upon
What is output by the code below?
int b = -5;
if( b > 100)
out.print("go");
else if( b > 90)
out.print("it");
else
out.print("up");
out.print("on");
itupon
on
iton
upon
goon
What is output by the code below?

for(int i=0; i<=10; i=i+2)
out.print(i);
02468
024681012
10
0246810
246810
What is output by the code below?
for(int i=5; i<20; i=i+3)
out.print(i);
581114
58111417
5811141720
581114172023
8111417
What is output by the code below?
for(int i=15; i>2; i=i-2)
System.out.print(i);
15131197531-1
151311975
13119753
1513119753
15131197531
What is output by the code below?
int ans = 0;
for(int i=10; i>-1; i=i-2)
ans += i;
System.out.print( ans );
25
27
32
29
30
What is output by the code below?
int ans = 0;
for(int i=0; i<12; i=i+3)
ans += i;
System.out.print( ans );
25
30
18
20
27
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 );
27
30
20
25
36
What is returned by the call go( 7 ) ?
public static String go( int x)
{
String s = "";
for(int n = x; n > 0; n = n - 2)
s = s + n + " ";
return s;
}
7 5
7 5 3
7 5 3 1
7
1
What is returned by the call go( 17 ) ?
public static int go( int x)
{
int val = 0;
for(int n = 1; n < x; n = n + 4)
val = val + n;
return val;
}
20
24
28
22
25
What is returned by the call go( 7, 12 ) ?
public static int go( int x, int y)
{
int cnt = 0;
for(int n = x; n < y; n = n + 1)
if(n % 2 != 0 )
cnt++;
return cnt;
}
5
2
3
6
4