Online visitors

People learning around the world

Online

—

Visitors exploring W3Schools

Online visitors by country Circles show approximate country locations. The country list provides the visitor counts.

Circles represent countries, not exact visitor locations.

Country

Online

Loading country activity…

    Java Assignment Operators

    Java Programming Tutorials


    The Java Assignment Operators are used when you want to assign a value to the expression. The assignment operator denoted by the single equal sign =.

    In a Java assignment statement, any expression can be on the right side and the left side must be a variable name. For example, this does not mean that "a" is equal to "b", instead, it means assigning the value of 'b' to 'a'. It is as follows:

    Syntax:

    variable = expression;

    Example:

    int a = 6;
    float b = 6.8F;

    Java also has the facility of chain assignment operators, where we can specify a single value for multiple variables.

    Example:

    public class ChainAssign {
        public static void main(String args[]) {
            int a, b, c;
            a = b = c = 100; // set a, b, and c to 100
            System.out.println("a = " + a);
            System.out.println("b = " + b);
            System.out.println("c = " + c);
        }
    }

    Output:

    a = 100
    b = 100
    c = 100


    Found This Page Useful? Share It!
    Get the Latest Tutorials and Updates
    Join us on Telegram

    Notifications

    Updates are enabled for this browser.

    Receive new tutorials, articles and learning resources. You can turn updates off anytime.