Semester Final Review

Last updated over 1 year ago
130 questions
1

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

1

What is the ASCII value of a space?

1

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

1

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

1

What is the output by the code below?
System.out.println("Hello ");
System.out.print("people ");
System.out.println("everywhere ");

1

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

1

What is the output by the code below?
int num = 5;
System.out.println("num");

1

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

1

What is the output by the code below?
char c = 65;
System.out.println(c);

1

Which of the following lines correctly defines a char variable?

1

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

1

Which of the following is the tab character?

1

Which of the following lines correctly defines a String variable?

1

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

1

What is the output by the code below?
int cost = 2.65;
System.out.println("Price: " + cost);

1

What is the output by the code below?
String s = "aplus";
System.out.println( s );

1

In Java, every program statement ends with a what ?

1

Every method must have an open and close what?

1

What is the output by the code below?
System.out.print( "ap\\lus" );

1

Which of the following is a 32 bit data type?

4

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

4

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

4

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

4

Given the following statement, var must be defined as which of the following types?
var=keyboard.nextFloat();

4

Given the following statement, var must be defined as which of the following types?
var=keyboard.nextLine();

4

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

4

Given the following statement, var must be defined as which of the following types?
var=keyboard.nextLong();

4

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

4

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

4

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

4

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

4

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

4

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

4

Which of the following Scanner methods can be used to read in the value
”apluscompsci is the best” ?

4

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

4

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

4

Given the following statement, var must be defined as which of the following types?
var=keyboard.next();

4

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

4

Given the following statement, var must be defined as which of the following types?
var=keyboard.nextByte();

4

Given the following statement, var must be defined as which of the following types?
var=keyboard.nextDouble();

1

What is output by the code below?
double x = .5 + .5;
System.out.print(x);

1

What is output by the code below?
int x = 1;
x *= 5;
System.out.print(x);

1

What is output by the code below?
System.out.print( 4 - 3 );

1

What is output by the code below?
System.out.print(4 % 3);

1

What is output by the code below?
System.out.print( (int)9.6 );

1

What is output by the code below?
int x = 12,
y = 20;
int z = x + y;
double a = z;
System.out.print(a);

1

What is output by the code below?
System.out.println( 7 / 0);

4

What is output by the code below?

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

4

What is output by the code below?

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

4

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

4

What is output by the code below?

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

4

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

4

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

4

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

4

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

4

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

4

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

4

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

4

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

4

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

4

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

4

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

4

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

4

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

4

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

4

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

4

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

2.5

What is output by the code below?

String s = "apluscompsci";
System.out.println( s.substring(4,5) );

2.5

What is output by the code below?

String s = "apluscompsci";
System.out.println( s.substring( s.length()-1 ) );

2.5

What is output by the code below?

String s = "apluscompsci";
System.out.println( s.charAt( s.length()-3 ) );

2.5

What is output by the code below?

String s = "apluscompsci";
System.out.println( s.charAt(0) );

2.5

What is output by the code below?

String s = "apluscompsci";
System.out.println( s.charAt(5) );

2.5

What is output by the code below?

String s = "apluscompsci";
System.out.println( s.indexOf( "s" ) );

2.5

What is output by the code below?

String s = "apluscompsci";
System.out.println( s.indexOf( "apluscomp" ) );

2.5

What is output by the code below?

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

2.5

What is output by the code below?

String s = "apluscompsci";
System.out.println( s.substring( 6 ) );

2.5

What is output by the code below?

String s = "apluscompsci";
System.out.println( s.indexOf( "b" ) );

2.5

What is output by the code below?

String s = "apluscompsci";
int x = s.indexOf( "c" );
System.out.println( s.substring( x ) );

2.5

What is output by the code below?

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

2.5

What is output by the code below?

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

2.5

What is output by the code below?

String s = "apluscompsci";
System.out.println( s.substring(0,2) );

2.5

What is output by the code below?

String s = "apluscompsci";
int x = 3;
System.out.println( s.substring(x,x+1) );

2.5

What is output by the code below?

String s = "dog";
String r = "dog ";
System.out.println( s.equals( r ) );

2.5

What is output by the code below?

String s = "dog ";
String r = new String("dog");
System.out.println( s.equals( r ) );

2.5

What is output by the code below?

String s = "dog";
String r = new String("dog");
System.out.println( s != r );

2.5

What is output by the code below?

String s = "dog";
String r = "dog";
r = s;
s = null;
System.out.println( r );

2.5

What is output by the code below?

String s = "dog";
String r = s;
s = null;
System.out.println( s );

2.5

What is output by the code below?

String s = "Big dog";
String r = "A dog";
System.out.println( s.compareTo(r) );

2.5

What is output by the code below?

String s = "dog";
String r = "cog";
System.out.println( r.compareTo(s) );

2.5

What is output by the code below?

String s = "dodge";
String r = "cloths";
System.out.println( s.compareTo(r) );

2.5

What is output by the code below?

String s = "bob";
String r = "bod";
System.out.println( s.compareTo(r) );

2.5

What is output by the code below?

String s = 12;
int x = Integer.parseInt( s );
System.out.println( x + 3 );

2.5

What is output by the code below?

String s = "12.7";
Double x = Double.parseDouble( s );
System.out.println( x + 3 );

2.5

What is output by the code below?

String s = "12.7";
double x = Double.parseDouble( s );
System.out.println( x + 3 );

2.5

What is output by the code below?

String s = "12";
int x = Integer.parseInt( s );
System.out.println( s + x + 3 );

2.5

What is output by the code below?

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

2.5

What is returned by the call myst("aplus","aplus")?
public boolean myst(String a, String b)
{
return a.equals( b );
}

2.5

What is returned by the call myst("aplus","aplus")?
public boolean myst(String a, String b)
{
return a == b;
}

2.5

What is returned by the call myst("ana","banana")?
public boolean myst(String a, String b)
{
return b.lastIndexOf(a)!=b.indexOf(a);
}

2.5

What is the purpose of myst?
public boolean myst(String a, String b)
{
return b.lastIndexOf(a)!=b.indexOf(a);
}

8.75

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

8.75

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?

8.75

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?

8.75

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

8.75

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

8.75

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?

8.75

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?

8.75

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

1

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

1

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

1

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

1

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

1

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

1

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

1

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

1

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

1

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

1

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

1

What is output by the code below?

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

1

What is output by the code below?
for(int i=5; i<20; i=i+3)
out.print(i);

1

What is output by the code below?
for(int i=15; i>2; i=i-2)
System.out.print(i);

1

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

1

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

1

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

1

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

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

1

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

1

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

1

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

1

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