Given an integer variable 'x' initially set to '5', you are required to increment the value of 'x' by '1' and then decrement it by '1' afterwards. Your result should be displayed on the console both after the increment and after the decrement operations. The lines of code you need are provided, but they are out of order. Reorder the lines of code to solve the task. Note: You are not allowed to modify the existing code or add any code except for the necessary import statements.
Increment and decrement
Incrementing and decrementing a variable
Report a typo
Reorder lines using drag or arrows. Adjust indentation with left buttons
x++; // Increment using "++" operator
}
public class Main {
}
int x = 5;
System.out.println("After increment: " + x);
public static void main(String[] args) {
System.out.println("After decrement: " + x);
x--; // Decrement using "--" operator
___
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.