Twa kɔ nsɛm atitiriw so
Log in
Sign up for FREE
arrow_back
Laabri

Semester Final Review

star
star
star
star
star
Last updated over 2 years ago
130 Nsɛmmisa
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
Asemmisa {{asɛmmisaAhyɛnsode}}
1.

What is the output by the code below?

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

Asemmisa {{asɛmmisaAhyɛnsode}}
2.

What is the ASCII value of a space?

Asemmisa {{asɛmmisaAhyɛnsode}}
3.

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

Asemmisa {{asɛmmisaAhyɛnsode}}
4.

What is output by the following code?

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

Asemmisa {{asɛmmisaAhyɛnsode}}
5.

What is the output by the code below?

System.out.println("Hello ");

System.out.print("people ");

System.out.println("everywhere ");

Asemmisa {{asɛmmisaAhyɛnsode}}
6.

What is output by the following code?

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

Asemmisa {{asɛmmisaAhyɛnsode}}
7.

What is the output by the code below?

int num = 5;

System.out.println("num");

Asemmisa {{asɛmmisaAhyɛnsode}}
8.

What is the output by the code below?

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

Asemmisa {{asɛmmisaAhyɛnsode}}
9.

What is the output by the code below?

char c = 65;

System.out.println(c);

Asemmisa {{asɛmmisaAhyɛnsode}}
10.

Which of the following lines correctly defines a char variable?

Asemmisa {{asɛmmisaAhyɛnsode}}
11.

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

Asemmisa {{asɛmmisaAhyɛnsode}}
12.

Which of the following is the tab character?

Asemmisa {{asɛmmisaAhyɛnsode}}
13.

Which of the following lines correctly defines a String variable?

Asemmisa {{asɛmmisaAhyɛnsode}}
14.

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

Asemmisa {{asɛmmisaAhyɛnsode}}
15.

What is the output by the code below?

int cost = 2.65;

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

Asemmisa {{asɛmmisaAhyɛnsode}}
16.

What is the output by the code below?

String s = "aplus";

System.out.println( s );

Asemmisa {{asɛmmisaAhyɛnsode}}
17.

In Java, every program statement ends with a what ?

Asemmisa {{asɛmmisaAhyɛnsode}}
18.

Every method must have an open and close what?

Asemmisa {{asɛmmisaAhyɛnsode}}
19.

What is the output by the code below?

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

Asemmisa {{asɛmmisaAhyɛnsode}}
20.

Which of the following is a 32 bit data type?

Asemmisa {{asɛmmisaAhyɛnsode}}
21.

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

Asemmisa {{asɛmmisaAhyɛnsode}}
22.

Which of the following Scanner methods can be used to read in a line of words?

Asemmisa {{asɛmmisaAhyɛnsode}}
23.

Which of the following Scanner methods can be used to read in the value “apluscompsciisthebest” ?

Asemmisa {{asɛmmisaAhyɛnsode}}
24.

Given the following statement, var must be defined as which of the following types?

var=keyboard.nextFloat();

Asemmisa {{asɛmmisaAhyɛnsode}}
25.

Given the following statement, var must be defined as which of the following types?

var=keyboard.nextLine();

Asemmisa {{asɛmmisaAhyɛnsode}}
26.

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

Asemmisa {{asɛmmisaAhyɛnsode}}
27.

Given the following statement, var must be defined as which of the following types?

var=keyboard.nextLong();

Asemmisa {{asɛmmisaAhyɛnsode}}
28.

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

Asemmisa {{asɛmmisaAhyɛnsode}}
29.

Which of the following is the Java class used for input?

Asemmisa {{asɛmmisaAhyɛnsode}}
30.

Which of the following is used in the Scanner constructor to connect to the keyboard?

Asemmisa {{asɛmmisaAhyɛnsode}}
31.

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

Asemmisa {{asɛmmisaAhyɛnsode}}
32.

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

Asemmisa {{asɛmmisaAhyɛnsode}}
33.

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

Asemmisa {{asɛmmisaAhyɛnsode}}
34.

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

”apluscompsci is the best” ?

Asemmisa {{asɛmmisaAhyɛnsode}}
35.

Which of the following would correctly define and instantiate a Scanner?

Asemmisa {{asɛmmisaAhyɛnsode}}
36.

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

Asemmisa {{asɛmmisaAhyɛnsode}}
37.

Given the following statement, var must be defined as which of the following types?

var=keyboard.next();

Asemmisa {{asɛmmisaAhyɛnsode}}
38.

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

Asemmisa {{asɛmmisaAhyɛnsode}}
39.

Given the following statement, var must be defined as which of the following types?

var=keyboard.nextByte();

Asemmisa {{asɛmmisaAhyɛnsode}}
40.

Given the following statement, var must be defined as which of the following types?

var=keyboard.nextDouble();

Asemmisa {{asɛmmisaAhyɛnsode}}
41.

What is output by the code below?

double x = .5 + .5;

System.out.print(x);

Asemmisa {{asɛmmisaAhyɛnsode}}
42.

What is output by the code below?

int x = 1;

x *= 5;

System.out.print(x);

Asemmisa {{asɛmmisaAhyɛnsode}}
43.

What is output by the code below?

System.out.print( 4 - 3 );

Asemmisa {{asɛmmisaAhyɛnsode}}
44.

What is output by the code below?

System.out.print(4 % 3);

Asemmisa {{asɛmmisaAhyɛnsode}}
45.

What is output by the code below?

System.out.print( (int)9.6 );

Asemmisa {{asɛmmisaAhyɛnsode}}
46.

What is output by the code below?

int x = 12,

y = 20;

int z = x + y;

double a = z;

System.out.print(a);

Asemmisa {{asɛmmisaAhyɛnsode}}
47.

What is output by the code below?

System.out.println( 7 / 0);

Asemmisa {{asɛmmisaAhyɛnsode}}
48.

What is output by the code below?

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

Asemmisa {{asɛmmisaAhyɛnsode}}
49.

What is output by the code below?

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

Asemmisa {{asɛmmisaAhyɛnsode}}
50.

What is output by the code below?

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

Asemmisa {{asɛmmisaAhyɛnsode}}
51.

What is output by the code below?

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

Asemmisa {{asɛmmisaAhyɛnsode}}
52.

What is output by the code below?

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

Asemmisa {{asɛmmisaAhyɛnsode}}
53.

What is output by the code below?

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

Asemmisa {{asɛmmisaAhyɛnsode}}
54.

What is output by the code below?

System.out.println( Math.max(26,18) );

Asemmisa {{asɛmmisaAhyɛnsode}}
55.

What is output by the code below?

System.out.println( Math.min(36,8) );

Asemmisa {{asɛmmisaAhyɛnsode}}
56.

What is output by the code below?

System.out.println( Math.sqrt(64) );

Asemmisa {{asɛmmisaAhyɛnsode}}
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 ) );

Asemmisa {{asɛmmisaAhyɛnsode}}
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 ) );

Asemmisa {{asɛmmisaAhyɛnsode}}
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) );

Asemmisa {{asɛmmisaAhyɛnsode}}
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) );

Asemmisa {{asɛmmisaAhyɛnsode}}
61.

How many methods does Bird contain?

public class Bird

{

public void speak()

{

out.println("chirp-chirp");

}

public void sayName()

{

out.println("baby bird");

}

}

Asemmisa {{asɛmmisaAhyɛnsode}}
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");

}

}

Asemmisa {{asɛmmisaAhyɛnsode}}
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();

Asemmisa {{asɛmmisaAhyɛnsode}}
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();

Asemmisa {{asɛmmisaAhyɛnsode}}
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();

Asemmisa {{asɛmmisaAhyɛnsode}}
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();

Asemmisa {{asɛmmisaAhyɛnsode}}
67.

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();

Asemmisa {{asɛmmisaAhyɛnsode}}
68.

What is output by the code below?

String s = "apluscompsci";

System.out.println( s.substring(4,5) );

Asemmisa {{asɛmmisaAhyɛnsode}}
69.

What is output by the code below?

String s = "apluscompsci";

System.out.println( s.substring( s.length()-1 ) );

Asemmisa {{asɛmmisaAhyɛnsode}}
70.

What is output by the code below?

String s = "apluscompsci";

System.out.println( s.charAt( s.length()-3 ) );

Asemmisa {{asɛmmisaAhyɛnsode}}
71.

What is output by the code below?

String s = "apluscompsci";

System.out.println( s.charAt(0) );

Asemmisa {{asɛmmisaAhyɛnsode}}
72.

What is output by the code below?

String s = "apluscompsci";

System.out.println( s.charAt(5) );

Asemmisa {{asɛmmisaAhyɛnsode}}
73.

What is output by the code below?

String s = "apluscompsci";

System.out.println( s.indexOf( "s" ) );

Asemmisa {{asɛmmisaAhyɛnsode}}
74.

What is output by the code below?

String s = "apluscompsci";

System.out.println( s.indexOf( "apluscomp" ) );

Asemmisa {{asɛmmisaAhyɛnsode}}
75.

What is output by the code below?

String s = "ishouldofstudied";

System.out.println( s.length() );

Asemmisa {{asɛmmisaAhyɛnsode}}
76.

What is output by the code below?

String s = "apluscompsci";

System.out.println( s.substring( 6 ) );

Asemmisa {{asɛmmisaAhyɛnsode}}
77.

What is output by the code below?

String s = "apluscompsci";

System.out.println( s.indexOf( "b" ) );

Asemmisa {{asɛmmisaAhyɛnsode}}
78.

What is output by the code below?

String s = "apluscompsci";

int x = s.indexOf( "c" );

System.out.println( s.substring( x ) );

Asemmisa {{asɛmmisaAhyɛnsode}}
79.

What is output by the code below?

int x = "alligator".length() - "crocodile".length();

System.out.println( x );

Asemmisa {{asɛmmisaAhyɛnsode}}
80.

What is output by the code below?

int x = "crocodile".length() - "croc".length();

System.out.println( x );

Asemmisa {{asɛmmisaAhyɛnsode}}
81.

What is output by the code below?

String s = "apluscompsci";

System.out.println( s.substring(0,2) );

Asemmisa {{asɛmmisaAhyɛnsode}}
82.

What is output by the code below?

String s = "apluscompsci";

int x = 3;

System.out.println( s.substring(x,x+1) );

Asemmisa {{asɛmmisaAhyɛnsode}}
83.

What is output by the code below?

String s = "dog";

String r = "dog ";

System.out.println( s.equals( r ) );

Asemmisa {{asɛmmisaAhyɛnsode}}
84.

What is output by the code below?

String s = "dog ";

String r = new String("dog");

System.out.println( s.equals( r ) );

Asemmisa {{asɛmmisaAhyɛnsode}}
85.

What is output by the code below?

String s = "dog";

String r = new String("dog");

System.out.println( s != r );

Asemmisa {{asɛmmisaAhyɛnsode}}
86.

What is output by the code below?

String s = "dog";

String r = "dog";

r = s;

s = null;

System.out.println( r );

Asemmisa {{asɛmmisaAhyɛnsode}}
87.

What is output by the code below?

String s = "dog";

String r = s;

s = null;

System.out.println( s );

Asemmisa {{asɛmmisaAhyɛnsode}}
88.

What is output by the code below?

String s = "Big dog";

String r = "A dog";

System.out.println( s.compareTo(r) );

Asemmisa {{asɛmmisaAhyɛnsode}}
89.

What is output by the code below?

String s = "dog";

String r = "cog";

System.out.println( r.compareTo(s) );

Asemmisa {{asɛmmisaAhyɛnsode}}
90.

What is output by the code below?

String s = "dodge";

String r = "cloths";

System.out.println( s.compareTo(r) );

Asemmisa {{asɛmmisaAhyɛnsode}}
91.

What is output by the code below?

String s = "bob";

String r = "bod";

System.out.println( s.compareTo(r) );

Asemmisa {{asɛmmisaAhyɛnsode}}
92.

What is output by the code below?

String s = 12;

int x = Integer.parseInt( s );

System.out.println( x + 3 );

Asemmisa {{asɛmmisaAhyɛnsode}}
93.

What is output by the code below?

String s = "12.7";

Double x = Double.parseDouble( s );

System.out.println( x + 3 );

Asemmisa {{asɛmmisaAhyɛnsode}}
94.

What is output by the code below?

String s = "12.7";

double x = Double.parseDouble( s );

System.out.println( x + 3 );

Asemmisa {{asɛmmisaAhyɛnsode}}
95.

What is output by the code below?

String s = "12";

int x = Integer.parseInt( s );

System.out.println( s + x + 3 );

Asemmisa {{asɛmmisaAhyɛnsode}}
96.

What is output by the code below?

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

Asemmisa {{asɛmmisaAhyɛnsode}}
97.

What is returned by the call myst("aplus","aplus")?

public boolean myst(String a, String b)

{

return a.equals( b );

}

Asemmisa {{asɛmmisaAhyɛnsode}}
98.

What is returned by the call myst("aplus","aplus")?

public boolean myst(String a, String b)

{

return a == b;

}

Asemmisa {{asɛmmisaAhyɛnsode}}
99.

What is returned by the call myst("ana","banana")?

public boolean myst(String a, String b)

{

return b.lastIndexOf(a)!=b.indexOf(a);

}

Asemmisa {{asɛmmisaAhyɛnsode}}
100.

What is the purpose of myst?

public boolean myst(String a, String b)

{

return b.lastIndexOf(a)!=b.indexOf(a);

}

Asemmisa {{asɛmmisaAhyɛnsode}}
101.

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;

}

Asemmisa {{asɛmmisaAhyɛnsode}}
102.

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?

Asemmisa {{asɛmmisaAhyɛnsode}}
103.

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?

Asemmisa {{asɛmmisaAhyɛnsode}}
104.

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;

}

Asemmisa {{asɛmmisaAhyɛnsode}}
105.

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" );

Asemmisa {{asɛmmisaAhyɛnsode}}
106.

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?

Asemmisa {{asɛmmisaAhyɛnsode}}
107.

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?

Asemmisa {{asɛmmisaAhyɛnsode}}
108.

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);

Asemmisa {{asɛmmisaAhyɛnsode}}
109.

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");

Asemmisa {{asɛmmisaAhyɛnsode}}
110.

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");

Asemmisa {{asɛmmisaAhyɛnsode}}
111.

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");

Asemmisa {{asɛmmisaAhyɛnsode}}
112.

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");

Asemmisa {{asɛmmisaAhyɛnsode}}
113.

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;

}

Asemmisa {{asɛmmisaAhyɛnsode}}
114.

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;

}

Asemmisa {{asɛmmisaAhyɛnsode}}
115.

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);

Asemmisa {{asɛmmisaAhyɛnsode}}
116.

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;

}

Asemmisa {{asɛmmisaAhyɛnsode}}
117.

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");

Asemmisa {{asɛmmisaAhyɛnsode}}
118.

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");

Asemmisa {{asɛmmisaAhyɛnsode}}
119.

What is output by the code below?

for(int i=0; i<=10; i=i+2)

out.print(i);

Asemmisa {{asɛmmisaAhyɛnsode}}
120.

What is output by the code below?

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

out.print(i);

Asemmisa {{asɛmmisaAhyɛnsode}}
121.

What is output by the code below?

for(int i=15; i>2; i=i-2)

System.out.print(i);

Asemmisa {{asɛmmisaAhyɛnsode}}
122.

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 );

Asemmisa {{asɛmmisaAhyɛnsode}}
123.

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 );

Asemmisa {{asɛmmisaAhyɛnsode}}
124.

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 );

Asemmisa {{asɛmmisaAhyɛnsode}}
125.

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;

}

Asemmisa {{asɛmmisaAhyɛnsode}}
126.

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;

}

Asemmisa {{asɛmmisaAhyɛnsode}}
127.

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;

}

Asemmisa {{asɛmmisaAhyɛnsode}}
128.

int tot = 0;

for( int i=2; i<17; i++ ) {

tot = tot + i;

}

out.println( tot );

Asemmisa {{asɛmmisaAhyɛnsode}}
129.

int count=0;

for(int j=4; j<23; j++) {

if(j%2==1)

count++;

}

out.println( count );

Asemmisa {{asɛmmisaAhyɛnsode}}
130.

int sum=0;

for(int m=5; m<18; m++) {

if(m%2!=1)

sum=sum+m;

}

out.println(sum);