Using The Assignment Operator

The assignment operator is the single equal sign, =. It has this general form:


var = expression;

type of var must be compatible with the type of expression. The assignment operator allows you to create a chain of assignments.

 
public class Main {
  public static void main(String[] argv) {
    int x, y, z;
    x = y = z = 100; // set x, y, and z to 100
    System.out.println("x is " + x);
    System.out.println("y is " + y);
    System.out.println("z is " + z);
  }
}

The output:


x is 100
y is 100
z is 100
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.