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
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.