Question 1 What is the value of the value variable at the end of the given code
ID: 1416591 • Letter: Q
Question
Question 1
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 2
What will be printed by the statements below?
final int BONUS = 20;
int salary = 100;
int netSalary = salary + BONUS;
System.out.print(netSalary);
Question 3
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 4
What is result of evaluating the following expression?
(45 / 6) % 5
Question 5
What is the value of the following expression?
3 * 5 / 2 * 5
Question 6
What is the value of the following expression in Java?
2 + 3 + 5 / 2
Question 7
Assuming that the user inputs a value of 25 for the price and 10 for the discount rate in the following code snippet, what is the output?
Scanner in = new Scanner(System.in);
System.out.print("Enter the price: ");
double price = in.nextDouble();
System.out.print("Enter the discount rate: ");
double discount = in.nextDouble();
System.out.println("The new price is " + (price - price * (discount / 100.0)));
Question 8
Assuming that the user inputs “Joe” at the prompt, what is the output of the following code snippet?
System.out.print("Enter your name ");
String name;
Scanner in = new Scanner(System.in);
name = in.next();
name += ", Good morning";
System.out.print(name);
Question 9
What will be the value of the variables a and b after the given set of assignments?
int a = 20;
int b = 10;
a = (a + b) / 2;
b = a;
a++;
Value of a:
Value of b:
Question 10
What is the output of the following code snippet?
System.out.printf("%5.3f", 20.0);
Bottom of Form
Explanation / Answer
1. It will be -2. ++ operator increases it by 1 after 2nd line stores -3 as value.
2. 120. net salary is defined as a sum of 100 and 20.
3. Hry. n will be 5. mystery will be "H" + "ry".
4. 2.
5. 35. Here operator precedence is same but associativity will be followed from left to right.
6. 7. Here / precedence is higher than +.
7. Output: The new price is 22.5
8. Output: Joe, Good morning
9. a=16,b=15.
10 20.000
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.