What is the output of the following code?public class Solution { public static void main(String args[]) { int x = 7--2; System.out.println(x); }}
Question
What is the output of the following code?public class Solution { public static void main(String args[]) { int x = 7--2; System.out.println(x); }}
Solution
The code you provided is not valid. In Java, the decrement operator (--) should be used with a variable, not a number. The correct usage would be something like this:
public class Solution {
public static void main(String args[]) {
int x = 7;
x = x - 2;
System.out.println(x);
}
}
In this case, the output would be 5.
Similar Questions
What is the output of the following code?public class Solution { public void display() { int x = 10; } public static void main(String args[]) { System.out.println(x); }}Options: Pick one correct answer from below100Compile time errorRuntime error
e correct answerWhat is the output of the following Java program?class Main { public static void main(String args[]) { final int i; i = 20; i = 30; System.out.println(i); }}
What will be the output of the following code snippet?int x = 7;int y = x > 5 ? 10 : 5;System.out.println(y);Question 29Answera.7b.5c.10d.The code will produce an error
What is the output of this program? class Output { public static void main(String args[]) { int a1[] = new int[10]; int a2[] = {1, 2, 3, 4, 5}; System.out.println(a1.length + " " + a2.length); } }Select one:a.0 5b.10 5c.5 10d.0 10
Find the output of the following code.class Output { public static void main(String args[]) { int arr[] = {11, 21, 31, 41, 51}; for ( int i = 1; i < arr.length - 2; ++i) System.out.println(arr[i] + " "); } }*11 21 31 4111 21 3121 3131 41 51
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.