Fill This Form To Receive Instant Help

Help in Homework
trustpilot ratings
google ratings


Homework answers / question archive / 1

1

Computer Science

1. If you have to iterate through an image, looking at each column, and then while you are in a particular column, looking at the pixel in each row, what would be the appropriate for loop setup?

 

A. for (int x=0; x< getWidth(); x++) {

 

            for (int y = 0; y < getHeight(); y++) { ...

 

B. for (int y = 0; y < getHeight(); y++) {

              for (int x = 0; x < getWidth(); x++) { ....

 

C.for (int i = 0; i < pixelArray.length; i ++) { ....

 

D. for (int x = 0; x < getHeight(); x++) {

              for (int y = 0; y < getWidth(); y++) { ...

 

E. for (int m = 0; m < getHeight(); m++) {

              for (int n = 0; n < getWidth(); n++) { ...

 

2. If you have to make the same change to every single pixel in an image (such as darken it), which code below will get you access to all the pixels you need?

 

A. for (int x = 0; x < getWidth(); x++) { 

              for (int y = 0; y < getHeight(); y++) {   ...

 

B. for (int y = 0; y < getHeight(); y++) {

             for (int x = 0; x < getWidth(); x++) {   ...

 

C. for (int i = 0; i < pixelArray.length; i++) { ...

 

D. int index = 0;

           while (index < pixelArray.length) {  ...  

               index = index + 1;

            }

 

E. for (Pixel pixelObj : pixelArray) { ...

 

F. All the above

 

3. If you had to make a change to the bottom right quadrant of an image, how would you get access to only those pixels?

 

A. for (int x = getWidth()/2; x < getWidth(); x++) {

 

   B.    for (int y = getHeight()/2; y < getHeight(); y++) {

         pixelObj = getPixel(x, y);    ...

 

C. for (int x = 0; x < getWidth()/2; x++) {

       for (int y = 0; y < getHeight()/2; y++) {

         pixelObj = getPixel(x, y);    ...

 

D. for (int i = (int)(pixelArray.length*0.75); i <     

                        pixelArray.length; i++) {

             pixelObj = pixelArray[i];  ...

 

E. int index = (int)(pixelArray.length*0.75);

          while (index < pixelArray.length) {

          pixelObj = pixelArray[i];

              index++;  ...

 

F. C & D

 

4. How many times will the following code print out "ITSC 1212"?

 

for (int i = 0; i < 25; i++) {

  for (int j = 0; j < 10; j++) {

   System.out.println(i + ", " + j);

   System.out.println("ITSC 1212");

  }

}

 

A. 25

 

B. 10

 

C. 35

 

D. 250

 

E. Forever, it's an infinite loop

 

5. How many times will the following code print out "ITSC 1212"?

 

for (int i = 0; i < 25; i++) {

 for (int j = 0; j < 10; ) {

   System.out.println(i + ", " + j);

   System.out.println("ITSC 1212");

 }

}

 

A. 25

 

B. 10

 

C. 35

 

D. 250

 

E. Forever, it's an infinite loop

 

6. How many times will the following code print out "ITSC 1212"?

 

for (int i = 0; i < 25; i++) {

 for (int j = 0; j < 10; j++ ) {

   System.out.println(i + ", " + j);

 }

 System.out.println("ITSC 1212");

}

 

A. 25

 

B. 10

 

C. 35

 

D. 250

 

E. Forever, it's an infinite loop

 

7. How many times will the following code print out "ITSC 1212"?

 

for (int i = 0; i < 25; i++) {

 for (int j = 0; j < 10; j++ ) {

  for (int k = 0; k < 4; k++) {

   System.out.println(i+","+j+","+k);

   System.out.println("ITSC 1212");

  }

 }

}

 

A. 25

 

B. 10

 

C. 4

 

D. 250

 

E. 1000

 

F. Forever, it's an infinite loop

 

8. The following code creates a 2D array of integers, and the nested for loops populate the array so that it is a multiplication table. In the last line of code, what should the array indices be in order to print out the correct answer (i.e., what replaces the question marks)?

 

A. 2 and 4

 

B. 3 and 5

 

C. 4 and 2

 

D. 1 and 3

 

E. 3 and 1

 

 9. Assuming the same code from the last question: String[][] bestActressAANominees = new String[5][2];bestActressAANominees[0][0] = "Jessica";bestActressAANominees[0][1] = "Chastain";... How would you get a count of the number of nominees whose last name is shorter than their first name? (Hint: the length() method tells you how many characters are in a String).

 

A. int numLastNameShorter = 0;for (int i = 0; i < 5; i++) {  if (bestActressAANominees[i][0].length() > bestActressAANominees[i][1].length()) {     numLastNameShorter = numLastNameShorter + 1;  }}

 

B. int numLastNameShorter = 0;for (int i = 0; i < 5; i++) {  if (bestActressAANominees[i][0].length() < bestActressAANominees[i][1].length()) {     numLastNameShorter = numLastNameShorter + 1;  }}

 

C. int numLastNameShorter = 0;for (int i = 0; i < 5; i++) {  if (bestActressAANominees[0][i].length() > bestActressAANominees[1][i].length()) {     numLastNameShorter = numLastNameShorter + 1;  }}

 

D. int numLastNameShorter = 0;for (int i = 0; i < 5; i++) {  if (bestActressAANominees[i][0].length() > bestActressAANominees[1][i].length()) {     numLastNameShorter = numLastNameShorter + 1;  }}

 

10. How would you initialize a 2D array of doubles called heightWeight that represents the height and weight of the 25 members of the UNC Charlotte football team? (you can have multiple answers)

 

A. double[][] heightWeight = new double[25][25];

 

B. double[][] heightWeight = new double[25][2]; 

 

C. double[] heightWeight = new double[50];

 

D. double heightWeight[] = new double[25,2];

 

11. Assuming you have initialized the heightWeight array from the previous question like this:

 

double[][] heightWeight = new double[25][2];

heightWeight[0][0] = 6.4; //height

heightWeight[0][1] = 270.0; // weight

...

 

How would you find out which player is the tallest? 

 

A. int tallest_index = 0;

 

       for (int i = 1; i < 25; i++) {

     if (heightWeight[i][0] > heightWeight[tallest_index][0])

             tallest_index = i;

       }

       System.out.println("The tallest player is at index " + tallest_index);

 

B. int tallest_index = 0;

for (int i = 1; i <= 25; i++) {

      if (heightWeight[i][0] > heightWeight[tallest_index][0]) 

           tallest_index = i;

    }

       System.out.println("The tallest player is at index " + tallest_index);

 

C. int tallest_index = 0;

       for (int i = 1; i < 25; i++) {

     if (heightWeight[i][0] > heightWeight[i-1][0])

       tallest_index = i;

    }

       System.out.println("The tallest player is at index " + tallest_index);

 

D. int tallest_index = 0;

       for (int i = 1; i < 2; i++) {

     for (int j = 0; j < 25; j++) {

       if (heightWeight[i][j] > heightWeight[tallest_index][j]) 

           tallest_index = i;

     }

    }

      System.out.println("The tallest player is at index " + tallest_index);

Purchase A New Answer

Custom new solution created by our subject matter experts

GET A QUOTE