Semester Final Review

By Mickey Arnold
Last updated 10 months ago
130 Questions

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

What is the ASCII value of a space?

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

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

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

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

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

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

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

Which of the following lines correctly defines a char variable?

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

Which of the following is the tab character?

Which of the following lines correctly defines a String variable?

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

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

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

In Java, every program statement ends with a what ?

Every method must have an open and close what?

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

Which of the following is a 32 bit data type?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

What is output by the code below?

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

What is output by the code below?

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

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

What is output by the code below?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

What is output by the code below?

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

What is output by the code below?

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

What is output by the code below?

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

What is output by the code below?

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

What is output by the code below?

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

What is output by the code below?

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

What is output by the code below?

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

What is output by the code below?

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

What is output by the code below?

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

What is output by the code below?

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

What is output by the code below?

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

What is output by the code below?

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

What is output by the code below?

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

What is output by the code below?

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

What is output by the code below?

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

What is output by the code below?

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

What is output by the code below?

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

What is output by the code below?

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

What is output by the code below?

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

What is output by the code below?

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

What is output by the code below?

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

What is output by the code below?

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

What is output by the code below?

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

What is output by the code below?

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

What is output by the code below?

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

What is output by the code below?

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

What is output by the code below?

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

What is output by the code below?

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

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

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

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

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

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

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?

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?

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

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

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?

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?

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

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

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

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

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

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

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

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

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

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

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

What is output by the code below?

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

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

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

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

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

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

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

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

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

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

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

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