>
Exams
>
Computer Science
>
Java Operators
>
what will be the output of the following java code
Question:
What will be the output of the following Java code?
public class Test {
public static void main(String[] args) {
int x = 5;
System.out.println(++x * 2);
}
}
Show Hint
Pre-increment (++x) updates the variable first, then that new value is multiplied.
CPET - 2025
CPET
Updated On:
Jul 2, 2026
12
10
8
14
Show Solution
Verified By Collegedunia
The Correct Option is
A
Solution and Explanation
Step 1:
Start with \( x = 5 \).
Step 2:
The operator
++x
is a pre-increment. It raises x by 1 before the value is used, so x becomes 6 and the expression uses 6.
Step 3:
Now multiply. \( 6 \times 2 = 12 \).
Step 4:
println prints 12. Answer is (A).
Download Solution in PDF
Was this answer helpful?
0
0
Top Odisha CPET Computer Science Questions
Which software process model involves small, iterative cycles with continuous customer feedback?
CPET - 2025
Computer Science
Software Engineering - Risk Management
View Solution
What does document.querySelector(".class") do?
CPET - 2025
Computer Science
Web Technology - PHP Arrays
View Solution
Which function is used to fetch a single row from a MySQL query result as an associative array?
CPET - 2025
Computer Science
Web Technology - PHP Arrays
View Solution
How do you loop through a multidimensional array in PHP?
CPET - 2025
Computer Science
Web Technology - PHP Arrays
View Solution
Which JavaScript function is used to change the style of an HTML element dynamically?
CPET - 2025
Computer Science
Web Technology - PHP Arrays
View Solution
View More Questions
Top Odisha CPET Java Operators Questions
What is the use of the final keyword in Java?
CPET - 2025
Computer Science
Java Operators
View Solution
What will be the output of the following Java code?
public class Check {
public static void main(String[] args) {
int a = 5;
System.out.println(a > 2 ? a < 5 ? 10 : 20 : 30);
}
}
CPET - 2025
Computer Science
Java Operators
View Solution
Top Odisha CPET Questions
What is the name (either correct name or synonym) of the causal agent of citrus canker disease ?
CPET - 2025
Plant Pathology
View Solution
Which one of the following is an example of doubly magic nuclei?
CPET - 2025
Nuclear physics
View Solution
A monobasic acid with a concentration of 0.04 M is dissociated to the extent of 0.5% in an aqueous solution. What is the dissociation constant of the acid?
CPET - 2025
Ionic Equilibrium
View Solution
Jackson (1953) divided meristems into three types. Which one is not one of those ?
CPET - 2025
Plant Anatomy
View Solution
As regards transcription, the prototype enhancer discovered in the animal virus SV40 is a sequence of __________ base pairs.
CPET - 2025
Molecular Biology
View Solution
View More Questions