The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | May 2017 |
| Last Sign in: | 399 Weeks Ago |
| Questions Answered: | 66690 |
| Tutorials Posted: | 66688 |
MCS,PHD
Argosy University/ Phoniex University/
Nov-2005 - Oct-2011
Professor
Phoniex University
Oct-2001 - Nov-2016
QUESTION 1
What is the error in the following code fragment?
double data[] = new double[20];
data[20] = 15.25;
| Â | A. |
A cast is required |
| Â | B. |
Out-of-bounds error |
| Â | C. |
A two-dimensional array is required |
| Â | D. |
Data not initialized |
4 points  Â
QUESTION 2
What is the value of sum after the following code fragment?
int sum = 0;
for (int i = 1; i <= 5; i++)
     sum = sum + i;
| Â | A. |
21 |
| Â | B. |
6 |
| Â | C. |
5 |
| Â | D. |
15 |
4 points  Â
QUESTION 3
What is the value of x after the following nested loop?
int x = 0;
for (int i = 0; i <= 3; i++)
   for (int j = 0; j < i; j++)
          x = x + j;
| Â | A. |
0 |
| Â | B. |
3 |
| Â | C. |
4 |
| Â | D. |
12 |
4 points  Â
QUESTION 4
Which of the following is equivalent to balance = balance + amount; ?
| Â | A. |
balance == amount; |
| Â | B. |
balance ++ amount; |
| Â | C. |
balance += amount; |
| Â | D. |
balance =+ amount; |
4 points  Â
QUESTION 5
Which of the following indicates that a method does not return a value?
| Â | A. |
void |
| Â | B. |
float |
| Â | C. |
double |
| Â | D. |
public |
4 points  Â
QUESTION 6
The Java compiler ignores any text between  ____.
| Â | A. |
/* and */ |
| Â | B. |
*/ and */ |
| Â | C. |
/# and #/ |
| Â | D. |
/ and / |
4 points  Â
QUESTION 7
Which one of the following is a valid header for a constructor for a class called Car?
| Â | A. |
Public void Car() |
| Â | B. |
public Car(String model) |
| Â | C. |
public class Car(String model) |
| Â | D. |
public car(String model) |
4 points  Â
QUESTION 8
In Java, the = operator
| Â | A. |
causes output to appear in the BlueJ Terminal Window |
| Â | B. |
tests for equality |
| Â | C. |
sets a variable to the given value |
| Â | D. |
has no definition |
4 points  Â
QUESTION 9
In Java, the statement
days++;
has the same effect as
| Â | A. |
days = days + 1; |
| Â | B. |
days = days + days; |
| Â | C. |
days + 1 = days; |
| Â | D. |
days = 1; |
4 points  Â
QUESTION 10
Which of the following are Java naming conventions?
#1:Â Â Â Â Â Â Â Classes start with an uppercase letter
#2:Â Â Â Â Â Â Â Methods (except for the constructor) start with an uppercase letter
#3:Â Â Â Â Â Â Â Objects start with a lowercase letter
#4:Â Â Â Â Â Â Â Objects start with an uppercase letter
#5:Â Â Â Â Â Â Â Classes start with a lowercase letter
#6:Â Â Â Â Â Â Â Methods (except for the constructor) start with a lowercase letter
| Â | A. |
#4, #5 and #6 |
| Â | B. |
#1, #2 and #4 |
| Â | C. |
#1, #3 and #6 |
| Â | D. |
#3, #5 and #6 |
4 points  Â
QUESTION 11
Given an array of int called scores, which of the following will access the first element of the array?
| Â | A. |
scores[1] |
| Â | B. |
scores.length - 1 |
| Â | C. |
scores.length |
| Â | D. |
scores[0] |
4 points  Â
QUESTION 12
Which of the following will allocate memory to hold an array of 10 int values?
| Â | A. |
int scores[] = new int[9]; |
| Â | B. |
int scores; |
| Â | C. |
int scores[] = new int[10]; |
| Â | D. |
int scores[]; |
4 points  Â
QUESTION 13
Re-write the following using a for loop
int z = 99;
while (z >= 12) {
   System.out.print("z is: ");
   System.out.println(z);
   z = z - 3;
}
System.out.println("done");
| Â | A. |
for (int z = 99; z >= 12; z = z - 3) { |
| Â | B. |
for (int z = 99; z >= 12; ++z) { |
| Â | C. |
for (int z = 99; z >= 12; z = z - 3) |
| Â | D. |
for (int z = 99; z >= 12; z = z - 3) { |
4 points  Â
QUESTION 14
What is the value of x after the following?
int x = 0;
for (int i = 2; i <= 14; i = i + 3)
   x = x + i;
| Â | A. |
0 |
| Â | B. |
26 |
| Â | C. |
40 |
| Â | D. |
57 |
4 points  Â
QUESTION 15
Given the following class definition:Â Â
public class Foo
{
   private int bar;
   public Foo(int i)
   {
       bar = i;
   }
   public void wah(int i)
   {
       bar = bar + i;
   }
   public void dah()
   {
       System.out.print(bar);
   }
}
and executing this code segment:
Foo f = new Foo(20);
f.wah(10);
f.dah();
What value will be output?
| Â | A. |
0 |
| Â | B. |
10 |
| Â | C. |
20 |
| Â | D. |
30 |
4 points  Â
QUESTION 16
Remember that the % operator evaluates to the remainder after integer division e.g. 8 % 4 is 0, 11 % 4 is 3.  What is the value of x after the following?
int x = 0;
for (int i = 1; i < 6; ++i)
   if (i % 2 == 0)
       x = x + i;
| Â | A. |
0 |
| Â | B. |
15 |
| Â | C. |
6 |
| Â | D. |
21 |
4 points  Â
QUESTION 17
Assume that mynums is an array of 5 integers. What will be the contents of mynums after the following code fragment?
for (int i = 0; i < 5; i++)
   mynums[i] = i + 1;
| Â | A. | 1 2 3 4 5 |
| Â | B. | 0 1 2 3 4 |
| Â | C. | 1 2 3 4 |
| Â | D. | 1 1 1 1 1 |
4 points  Â
QUESTION 18
What is the effect of the following code fragment?
for (double element : values) element = 0;
| Â | A. |
The elements of the array named values are initialized to zero |
| Â | B. |
The elements of the array named element are initialized to zero |
| Â | C. |
The first element of the array named values is initialized to zero |
| Â | D. |
The elements of the array named values are not modified |
4 points  Â
QUESTION 19
The following statement accesses the element at index 4 in an array:
x = a[4];
What is the equivalent operation using an array list?
| Â | A. |
x = a.get(4); |
| Â | B. |
x = a.get(); |
| Â | C. |
x = a.get[4]; |
| Â | D. |
x = a[4]; |
4 points  Â
QUESTION 20
Assume that values is an array of random integers. Which condition must be used in the indicated area so the code fragment below will set max to the largest value in values?
int max = values[0]; for (int val: values) { if (/* put condition here */) max = val; }
| Â | A. | max > val |
| Â | B. | val > max |
| Â | C. | values[val] > max |
| Â | D. | max > values[val] |
4 points  Â
QUESTION 21
Assume that names is an empty ArrayList of String. What will be the contents of names after the following code fragment?
names.add("Annie"); names.add("Bob"); names.add("Charles"); for (int i = 0; i < 3; i++) { String extra = names.get(i); names.add(extra);
}
| Â | A. |
Annie Bob Charles Annie Bob Charles |
| Â | B. |
Annie Bob Charles Charles Bob Annie |
| Â | C. |
Annie Annie Bob Bob Charles Charles |
| Â | D. |
Annie Bob Charles Bob Charles |
4 points  Â
QUESTION 22
What is the value of num after the following code fragment?
int num = 3; num++;
| Â | A. |
2 |
| Â | B. |
3 |
| Â | C. |
4 |
| Â | D. |
5 |
4 points  Â
QUESTION 23
What is the value of num after the following code fragment?
int num = 3; num = num A????1 2 * num; num++;
| Â | A. |
A????12 |
| Â | B. |
0 |
| Â | C. |
2 |
| Â | D. |
4 |
4 points  Â
QUESTION 24
What are the values of num1 and num2 after the following code fragment?
double num1 = 4.2;
double num2 = num1 * 10 + 5.0;
| Â | A. |
num1 is 4.2 and num2 is 63.0 |
| Â | B. |
num1 is 4.2 and num2 is 47.0 |
| Â | C. |
num1 is 42.0 and num2 is 42.0 |
| Â | D. |
num1 is 42.0 and num2 is 47.0 |
4 points  Â
QUESTION 25
What is the value of price after the following code fragment?
double price = 30.0; double discount = 10.0; price = price - price * (discount / 100.0);
| Â | A. |
30.0 |
| Â | B. |
20.0 |
| Â | C. |
27.0 |
| Â | D. |
33.0 |
Hel-----------lo -----------Sir-----------/Ma-----------dam----------- Â----------- Th-----------ank----------- Yo-----------u f-----------or -----------usi-----------ng -----------our----------- we-----------bsi-----------te -----------and----------- ac-----------qui-----------sit-----------ion----------- of----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill-----------