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

1. If String str3 = \"supercalifragilisticexpealidocious\", then what is the val

ID: 3801377 • Letter: 1

Question

1. If String str3 = "supercalifragilisticexpealidocious", then what is the value of str3.indexOf("li");?

2. If String str = "United States", then what is the value of str.indexOf("United");?

3. If String str = "Computer Science", then what is the value of str.substring(4, 6);?

4. If String str = "Computer Science", then what is the value of str.substring(10);?

5. If String str = "Lord of the Rings", then what is the value of str.length();?

6. If String str1 = "hello" and String str2 = "world", then what is the value of str1 + str2?

7. If String str = "United States", then what is the value of str.substring(2, 4);?

8. If String str = "supercalifragilisticexpealidocious", then what is the value of str.substring(21);?

9. A programmer knows that the value of the area of a triangle is 1/2 times the base times the height, and writes the following code:

int base = 7, height = 15;
double area = (double)((height * base) / 2);

What is wrong with this code?

Options:

Nothing is wrong with this code. It always correctly calculates the area.

10. Suppose that the variables grade1, grade2, and grade3 are declared as follows:

int grade1 = 88;
int grade2 = 92;
int grade3 = 83;

Which of these expressions correctly calculates the average of grade1, grade2, and grade3?

Options:

11.Which of these expressions evaluates to the integer value 3?

I. 6 / 2
II. 6.0 / 2
III. (int)(6.0 / 2)

Options:

12. What is the data type of this expression?

(3 + 4 / 3.14) + 5

13. What is the value of answer after the following code executes?

int answer = 0, number = 4;
answer = number * (number - 2) + 3 * 4;

Options:

14. What is the value of this expression?

int number = 3 + 5 / 2;

Options:

15. What is the value of this expression?

int number = 4 + 5 / 2;

Options:

1) The order of operations is incorrect. 2) It should be base * height, not height * base. 3) You do not need to cast the result to a double, because the area will always have an integer value. 4) The cast is applied too late. The integer result will be cast to a double, always ending in .0 5)

Nothing is wrong with this code. It always correctly calculates the area.

Explanation / Answer

1. 7 indexOf method will find the first occurence and return the index.
2. 0 the first occurence is at the 0th position
3. ut Returns a new string that is a substring of this string.(startIndex: inclusive endIndex: exclusive)
4. cience
5. 17
6. helloworld
7. it
8. xpealidocious
9. The cast is applied too late. The integer result will be cast to a double, always ending in .0
Correct code : double area = ((double)height * (double)base) / 2;
10. 5th option will work, but its hould be like ((double)grade1 + (double)grade2 + (double)grade3) / 3.0;    
11. 4th option (I. 6 / 2 and III. (int)(6.0 / 2))
12. 2nd option (double)
13. 2nd option (20)
14. 2nd option (5)  decimal value will be discarded
15. 4th option (6) decimal value will be discarded