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

Question 6 What is the output of the following code snippet? String str = \"Harr

ID: 3846214 • Letter: Q

Question

Question 6

What is the output of the following code snippet?

String str = "Harry";

int n = str.length();

String mystery = str.substring(0, 1) + str.substring(n - 2, n);

System.out.println(mystery);

Question 7

What is the output of the following code snippet?

String str1;

str1 = "I LOVE PEANUT BUTTER SANDWICHES";

String str2 = str1.substring(7, 13);

System.out.println(str2 + str1.length() / 10);

Question 8

What is the value of the value variable at the end of the given code snippet?

int value = 3;

value = value - 2 * value;

value++;

Question 9

What is the output of the following code snippet?

System.out.printf("%5.3f", 20.0);

Question 10

What is result of evaluating the following expression?

(45 / 6) % 5

Explanation / Answer

6.hry

8. 4

reason: first the value is initialized to 3 and later it is subtracted by 2 which would result 1 and then multipled by 3 i.e value=3-2 *3

=3

and later on it is incremented i.e 3++ which is equal to 4   

9. 20.000

10. 2

reason: division operator gives the quotient i.e 45/6 gives 7 as quotient and modulo operator gives remainder as result i.e this 7 when divided by 5 yields a remainder of 2

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote