COMP SCI REVIEW!!!

Ace your homework & exams now with Quizwiz!

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

-1

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

-1

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

-2

What is output by the code below? public class Check { private int one, two, total; public void setNums(int n1, int n2) { one = n1; two = n2; } public void add() { total = one + two; } public int getTotal() { return total; } } //code in the main of another class Check test = new Check(); test.setNums(3,-6); test.add(); out.println(test.getTotal());

-3

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

-5

System.out.println( Math.ceil(-6.7) );

-6.0

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

-7.0

System.out.print(12.7 % 3);

.7

How many methods are there in class Aplus? public class Aplus { private int val; private double num; }

0

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

0

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

0

System.out.print( 0 / 7 );

0

System.out.print( 8 / 10 );

0

int x = 15; x = x % 5; System.out.print(x);

0

What is output by the code below? public class Aplus { private double num; public Aplus() { num = 0.0; } public double go() { return num; } public void fun( int x ) { num = num + x; } } //code in the main of another class Aplus test = new Aplus(); System.out.println(test.go());

0.0

System.out.print( (double) 1 / 2 );

0.5

How many accessor methods are there in class Aplus? public class Aplus { private double num; public Aplus() { num = 0.0; } public double go() { return num; } public void fun( int x ) { num = num + x;} }

1

How many constructors are there in class Check? public class Check { private int one, two, total; public void setNums(int n1, int n2) { one = n1; two = n2; } public void add() { total = one + two; } public int getTotal() { return total;' } }

1

How many instance variables are there in class Aplus? public class Aplus { private int val; }

1

How many methods are there in class Aplus? public class Aplus { private double num; public Aplus() { num = 0.0; } public double go() { return num; } }

1

How many modifier / mutator methods are there in class Check? public class Check { private int one, two, total; public void setNums(int n1, int n2) { one = n1; two = n2; } public void add() { total = one + two; } public int getTotal() { return total; } }

1

How many mutator / modifier methods are there in class Aplus? public class Aplus { private double num; public Aplus() { num = 0.0; } public double go() { return num; } public void fun( int x ) { num = num + x; } }

1

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

1

System.out.print( 4 % 3);

1

System.out.print( 4 - 3 );

1

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

1

System.out.print( (double) 2 / 2);

1.0

double x = .5 + .5; System.out.print(x);

1.0

double x = 4/3; System.out.print(x);

1.0

double x = 5/3.0; System.out.print(x);

1.66

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

10.0

System.out.print(3.0 / 6 + 3 * 3.5);

11.0

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

12

System.out.println( Math.round(11.634) );

12

Consider the class and client code below. public class Aplus { public double go( double a ) { return a * 3; } public double fun( double b ) { return go( b ) + b; } } //client code in another class Aplus x = new Aplus(); System.out.println( x.fun(3) );

12.0

int x = 12, y = 2; int z = x * y; double a = z/2; System.out.print(a);

12.0

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

12123

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

1293

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

15

int x = 1 + 7 * 2; System.out.print(x);

15

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

15.7

System.out.println( Math.min(Math.min(16,18),17) );

16

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

16.0

System.out.println( Math.max(Math.min(16,18),17) );

17

int x = 15; System.out.print( x + 2 );

17

How many instance variables are there in class Aplus? public class Aplus { private int val; private double num; }

2

How many methods are there in class Aplus? public class Aplus { private double num; public Aplus() { num = 0.0; } public double go() {return num; } public void fun( int x ) {num = num + x;} }

2

System.out.println( Math.round(7 / 3) );

2

System.out.println( Math.round(7.0 / 3) );

2

int x = 1 + 7 % 2; System.out.print(x);

2

int x = 4; x—; x—; System.out.print(x);

2

How many instance variables are there in class Check? public class Check { private int one, two, total; public void setNums(int n1, int n2) { one = n1; two = n2; } public void add() { total = one + two; } public int getTotal() { return total; } }

3

int x = 15; x/= 5; System.out.print(x);

3

What is output by the code below? public class Aplus { private double num;public Aplus() { num = 0.0; } public double go() { return num; } public void fun( int x ) { num = num + x; } } //code in the main of another class Aplus test = new Aplus(); test.fun( 3 ); System.out.println(test.go());

3.0

int x = 12, y = 20; int z = x + y; double a = z; System.out.print(a);

32.0

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

36.0

System.out.print( 3 % 4 + 1 * 3 % 2 );

4

System.out.print( 4 % 3 + 1 * 3);

4

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

40

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

5

int x = 1; x *= 5; System.out.print(x);

5

int x = 4; x++; System.out.println(x);

5

int x = 5, y = 2; int z = x % y; double a = z * 5; System.out.println(a);

5.0

System.out.printf("%.3", 5.4517);

5.452

System.out.print( 8 - 4 + 2 );

6

Consider the class and client code below. public class Aplus { public double go( double a ) { return a * 3; } public double fun( double b ) { return go( b ) + b; } } //client code in another class Aplus x = new Aplus(); System.out.println( x.go(2) );

6.0

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

6.0

int x = 4; x *= 11 % 3; System.out.print(x);

8

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

8.0

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

9

System.out.print( 7 + 2 );

9

Consider the class and client code below. public class Aplus { public double go( double a ) { return a * 3; } public double fun( double b ) { return go( b ) + b; } } //client code in another class Aplus x = new Aplus(); System.out.println( x.go(3) );

9.0

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

9.0

Consider the method go below that should return the sum of the parameters a and b. public double go( double a, double b ) { /* blank */ } Which of the following could correctly fill /* blank */ ? I. return a + b; II. return a - b; III. return a * b;

I only

Consider the method go below that should return the perimeter of rectangle. The formula for perimeter of rectangle is :: 2 x length + 2 x width public double go( int len, int wid ) { /* blank */ } Which of the following could correctly fill /* blank */ ? I. return 2 * len * wid; II. return 2 * (len + wid); III. return 2 * len + 2 * wid;

II and III only

Consider the method go below that should return the difference of the parameters a and b. public double go( double a, double b ) { /* blank */ } Which of the following could correctly fill /* blank */ ? I. return a - b; II. return Math.abs(a - b); III. return a * b;

II only

Consider the method go below that should return twice the value of b minus the value of a. public double go( double a, double b ) { /* blank */ } Which of the following could correctly fill /* blank */ ? I. return b * b - a; II. return (2 * b) - a; III. return 2 * ( b - a );

II only

Consider the method go below that should return twice the value of a minus the value of b. public double go( double a, double b ) { /* blank */ } Which of the following could correctly fill /* blank */ ? I. return a * a - b; II. return 2 * a - b; III. return 2 * ( a - b );

II. return 2 * a - b;

Consider the method go below that should determine the value of a minus b and then return twice that value. public double go( double a, double b ) { /* blank */ } Which of the following could correctly fill /* blank */ ? I. return a * a - b; II. return 2 * a - b; III. return 2 * ( a - b );

III only

Consider the method go below that should return the perimeter of triangle. The formula for perimeter of a triangle is :: a + b + c public double go( int a, int b, int c ) { /* blank */ } Which of the following could correctly fill /* blank */ ? I. return abc; II. return a * b * c; III. return a + b + c;

III only

Consider the method go below that should return the product of the parameters a and b. public double go( double a, double b ) { /* blank */ } Which of the following could correctly fill /* blank */ ? I. return a + b; II. return a - b; III. return a * b;

III only

System.out.print( 7 / 0 );

There is no output due to a runtime error

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

There is no output due to an error.

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

a

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

a

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

compsci

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

dog

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

false

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

i

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

i

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

null

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

p

The instance variables in class Aplus have what access? public class Aplus { private int val; private double num; }

private

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

sci

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

true

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

true

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

true

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

u

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

u


Related study sets

MKT Research Exam 2 - Mindtap Q's

View Set

French quiz comparative and superlative 2/27/17 (chapter 6)

View Set

mktg 371 chapter 10- buying and disposing

View Set

Properties of Gases and Equations

View Set

Chapter 5 Chemistry Test Balentine

View Set

Chapter 19 Heart failure and dysrhythmias: Common sequelae of cardiac diseases

View Set