Java Arithmetic Operator increment and decrement result 2

Question

What is the output of the following code?

int x = 3; 
int answer = ++x * 10; 


40

Note

The prefixed operator causes the value of the x variable to be changed before the expression is evaluated.

The statement int?answer = ++x * 10 does the same thing, in order, as these statements:

x++; 
int answer = x * 10; 

public class Main {
  public static void main(String args[]) {
    int x = 3;//w  w  w  .  ja v  a2s  .c  o m
    int answer = ++x * 10;
    System.out.println(answer);

  }
}



PreviousNext

Related