Computer Science final guide

¡Supera tus tareas y exámenes ahora con Quizwiz!

If x and y both represent two-dimensional int arrays and have identically the same elements, what does the following print? System.out.println( Arrays.equals(x,y) );

false. (Arrays.equal doesnt work on a 2 dimensional array)

Show what the matrix a would look like after the following code executes: Arrays.fill(a[2], -156);

-156 -156 -156 -156

Which of the following is a possible output? Random rd = new Random( ); System.out.println( rd.nextInt(36) );

0

Show what the matrix a would look like after the following code executes: for (int row = 0; row < a.length; row++) { for(int col = 0; col < a[row].length; col++) a[row][col] = row * col; }

0 0 0 0 0 1 2 3 0 2 4 6

List all numbers that rndm.nextInt(10) might generate.

0 1 2 3 4 5 6 7 8 9

What range of random numbers does nextDouble( ) generate?

0-1

What is printed by the following? double d[][] = new double[8][25]; System.out.println(d[4][2]);

0.0

What is printed by the following? Arrays.sort(a[0]); System.out.println(Arrays.binarySearch(a[0],5));

1

To simulate the result of rolling a normal 6-sided die, what should replace <*1> public static int dieOutcome( ) { Random rdm = new Random( ); int die = <*1> return die; }

1 + rdm.nextInt(6);

What would be the range of possible values of db for the following line of code? double db = genRndDbl(4, 1); public static double genRndDbl(int m, int a) { Random r = new Random( ); double d = a + m * r.nextDouble( ); return d; }

1 < db < 5

What range of random numbers will this generate? d = 11 + 82.9 * rndm.nextDouble( );

11-93.9

What is printed by System.out.println(a[1][3]); ?

36

What range of random numbers will this generate? j = 201 + rndm.nextInt(46);

46-246

Show what the printout will look like: for (int row = 0; row < a.length; row++) { for(int col = 0; col < a[row].length; col++) { System.out.print(a[row][col] + "\t"); } System.out.println(" "); }

5 -16 9 21 22 19 -101 36 18 17 64 -2

Is it possible to use one of the sort methods of the Arrays class to sort a single row (index 3) of the two-dimensional matrix g? If so, show the code that will accomplish this.

Arrays.sort(g[3]);

The above table can be described as: (a) an Array (b) a Matrix (c) numbers that could be represented as subscripted variables (d) a, b, and c (e) none of these

D

Write code that will randomly generate numbers from the following set. Printout 10 such numbers. 18, 19, 20, 21, 22, 23, 24, 25

Random k= new Random(); k= 18+k.nextInt(8);

Write code that will create a Random object and then use it to generate and print 20 floating point numbers in the continuous range 22.5 < r < 32.5

Random p= new Random(); double r; for(int x=0;x<20; x++); r= 22.5+10* p.nextDouble();

Write code that will randomly generate and print 12 numbers from the following set. 100, 125, 150, 175

Random p= new random(); l= 100+25* p.nextInt(4);

Write code that will create an object called rd from the Random class.

Random rd= new Random();

Write a line of code that will print the number of rows in matrix a.

Sop(a.length);

Write a line of code that will print the number of columns (in matrix a) in the row given by index 2.

Sop(a[2].length);

Write a line of code that will printout the array element occupied by -101.

System.out.print(a[1][2]);

What is printed by the following? Arrays.sort(a[0]); System.out.println( Arrays.binarySearch(a[0],0) );

There is no 0. = returns a negative

Assuming that the Random class is "perfect" and generates all of the integers with equal probability, what is the probability that toss( ) returns a head?

exactly .5

Write a single line of code that will create the above integer array. Call the array a.

int a [] []= {5,-16,9,21}, {22,19,-101,36}, {18,17,64,-2};

Write a line of code to create a Random class object even though Random wasn't imported.

java.util Random r= new java.util. Random();

What import is necessary for the Random class?

java.util Random.*;

Is it possible to sort z (a two-dimensional array) with Arrays.sort(z); ?

no because you have to do it row by row.

What would be the replacement code for <*1> to generate random numbers from the following set? {20, 35, 50, 65} Random ri = new Random( ); int ri = <*1>

none

Which of the following is a possible output of the code to the right? java.util.Random rd = new java.util.Random( ); System.out.println( 1+ 5 * rd.nextDouble( ) );

none

Must all two-dimensional arrays have the same number of columns in each row?

nope

When a class has more than one method of the same name, this is called which of the following?

overloading

Which of the following "tosses" a Coin object named theCoin, and produces a true when the toss( ) method yields a HEADS?

toss==0


Conjuntos de estudio relacionados

ACC 330 True/False Final Exam Practice

View Set

PHOTO Test 1 Exposure, Shutter Speed, Bracketing, Equivalent Exposure

View Set

Chapter 7 Quiz Organizational Behavior

View Set