Java quiz please help best answer for most helpful and most correct?

DW25

New member
Mar 12, 2012
0
0
0
1. Complete this coding so that it prints the number 20.
double [ ] d = {30, 25, 20, 15};
System.out.println ( ________________ );



d[1]

d[2]

d[3]

d[20]

2.
Complete this coding to create a new array of doubles containing 100 values.
double [ ] item = ________________ ;


3.
Complete this coding to print the value in every component of an array named item.
for (int k = 0; k < ________________ ; k++)
System.out.println (item[k]);


4.
Complete this coding so that it doubles five of the numbers stored in an array.
for (int k = 3; k <= 7; k++)
item[k] = ________________ ;


5.
Complete this coding so that it replaces each of five of the numbers stored in an array by the square of that number.
for (int k = 3; k <= 7; k++)
item[k] = ________________ ;


6.
Complete this coding so that it prints the sum of five of the numbers stored in an array.
double sum = 0;
for (int k = 3; k <= 7; k++) ________________ ;
System.out.println (sum);


sum+=item[k]

sum=item[k]

sum=sum+item[k]

sum=item[k]+item[k]

7.
The phrase "while (k >= 0 && item[k] == given)" appears in some coding. That phrase is replaced by "while (item[k] == given && k >= 0)". Which of these four possibilities is then true?


there is no difference in effect

the loop may terminate earlier

the loop may terminate later

the program may crash in cases where it did not crash before

8.
Complete this coding to reverse the order in which the first 10 values occur in an array. The effect is that the 10 components will contain the same 10 values but in the opposite of their original order.
for (int k = 0; k < 10 ; k++)
item[k] = ________________ ;


9.
You have two arrays named b and c. You call a static method that swaps the value in component k of one array with the value in component k of the other array. This swap method does not mention any variable declared outside the method except its parameters. Which of the following method calls could possibly accomplish this?


swap (c, b, k);

swap (c[k], b[k]);

swap (c[k-1], b[k-1]);

swap (c[0], b[0]);

10.
Each component of the array age[ ] contains the age of the person whose ID number is in the corresponding component of id[ ]. Complete this for-loop to calculate how many of the first 10 people have an id that is greater than their age.
for (int k = 0; k < 10 ; k++)
if ( ________________ )
count++;


11.
The Car class has a method with the heading "public double getMiles()" that tells the number of miles that a particular Car object has been driven. We create an array of Cars using auto = new Car[10]. Complete this coding to add up the miles driven by all the Cars in the array.
double sum = 0;
for (int k = 0; k < 10; k++)
sum += ________________ ;


12.
The first 100 components of the int array x contain only 10 or 11 or 12. Complete this coding to count and print out how many of each of the three numbers there are.
int [] count = {0, 0, 0};
for (k = 0; k < 100; k++)
count [ ________________ ] ++;
System.out.println ("10s: " + count[0] + " 11s: " + count[1] + " 12s: " + count[2]);


13.
An array declared by g = new String [100] has a number of null values in it. Complete the following coding to move the values in the array around so that all the non-null values are at the front of the array (that is, in components g[0]...g[n] for some integer n) and all the null values are in the rest of the array.
int bottom = 0, top = 99;
while (bottom < top)
if (g[bottom] != null)
bottom++;
else
{ if (g[top] != null)
{ ________________ ;
g[top] = null;
}
top --;
}
 
Back
Top