Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

i\'m having problems with these problems on my homework. (These problems are sep

ID: 3666223 • Letter: I

Question

i'm having problems with these problems on my homework. (These problems are separate and not in one complete program)

1. Which of the following is true about the code below?

int[] nums = new int[5];

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

System.out.println(nums[i]);

}

Select one:

a. there are no errors

b. it will result in a compiler error only

c. it will result in a run-time error only

2.

If a and b are both int arrays, then a = b; will

Select one:

a. return true if each corresponding element of b is equal to each corresponding element of a (that is, a[0] is equal to b[0], a[1] is equal to b[1] and so forth) and return false otherwise

b. copy the 0th element of b into the 0th element of a

c. create an alias

d. return true if a and b are aliases and return false otherwise

e. copy all elements of b into a

3.

Arrays have a built in toString method that returns all of the elements in the array as one String with “ ” inserted between each element. This means you can put the name of the array inside a println statement and a nicely formatted list of values will print.

Select one:

a. True

b. False

4.

To swap the elements in positions 3 and 4 in an int array values, you would do:

values[3] = values[4];
values[4] = values[3];

Select one:

a. True

b. False

In Java, an array can only store one type of data. For instance, you cannot create an array that stores both double and String values.

Select one:

a. True

b. False

5.

An array, when instantiated, is fixed in size, but an ArrayList can dynamically change in size when new elements are added to it.

Select one:

a. True

b. False

6.

Fill in the missing code from the statement below. Write code only to complete this single statement- do not write additional statements.

The array flags should contain alternating boolean values (i.e., true at index 0, false at index 1, true at index 2, false at index 3, etc.)

for (int index = 0; index < flags.length; index++)

flags[index] = ??? your code here???? <-------answer there

7.

Write one statement that converts a String variable called word to uppercase and stores the result in the same variable.

For example, if word held "hello," after your statement, word would hold "HELLO."

Explanation / Answer

i'm having problems with these problems on my homework. (These problems are separate and not in one complete program)
1. Which of the following is true about the code below?
int[] nums = new int[5];
for(int i=0; i<=5; i++) {
System.out.println(nums[i]);
}
Select one:c(ArrayIndexOutOfBoundsException)
a. there are no errors
b. it will result in a compiler error only
c. it will result in a run-time error only

2.
If a and b are both int arrays, then a = b; will
Select one:e
a. return true if each corresponding element of b is equal to each corresponding element of a (that is, a[0] is equal to b[0], a[1] is equal to b[1] and so
forth) and return false otherwise
b. copy the 0th element of b into the 0th element of a
c. create an alias
d. return true if a and b are aliases and return false otherwise
e. copy all elements of b into a

3.
Arrays have a built in toString method that returns all of the elements in the array as one String with “ ” inserted between each element. This means you can
put the name of the array inside a println statement and a nicely formatted list of values will print.
Select one:a(Arrays.toString(array))-->[1,2,3....n]
a. True
b. False

4.
To swap the elements in positions 3 and 4 in an int array values, you would do:
values[3] = values[4];
values[4] = values[3];
Select one:b(need to take temp to hold position 3 element)
a. True
b. False

In Java, an array can only store one type of data. For instance, you cannot create an array that stores both double and String values.
Select one:a
a. True
b. False

5.
An array, when instantiated, is fixed in size, but an ArrayList can dynamically change in size when new elements are added to it.
Select one:a
a. True
b. False

6.
Fill in the missing code from the statement below. Write code only to complete this single statement- do not write additional statements.

The array flags should contain alternating boolean values (i.e., true at index 0, false at index 1, true at index 2, false at index 3, etc.)
for (int index = 0; index < flags.length; index++)
flags[index] = ??? your code here????
<-------answer there
for (int index = 0; index < flags.length; index++){
           flags[index] =(index%2==0);
       }


7.
Write one statement that converts a String variable called word to uppercase and stores the result in the same variable.
For example, if word held "hello," after your statement, word would hold "HELLO."
word=word.toUpperCase();