0% found this document useful (0 votes)
2 views7 pages

Java Assignment Operators 25

The document explains Java assignment operators, which are used to assign values to variables. It provides examples of various assignment operators such as =, +=, -=, and others, highlighting their functionality and equivalence to longer expressions. Additionally, it illustrates a real-life example of using the += operator to track savings.

Uploaded by

rathikaseenivas
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views7 pages

Java Assignment Operators 25

The document explains Java assignment operators, which are used to assign values to variables. It provides examples of various assignment operators such as =, +=, -=, and others, highlighting their functionality and equivalence to longer expressions. Additionally, it illustrates a real-life example of using the += operator to track savings.

Uploaded by

rathikaseenivas
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

3/12/26, 11:41 AM Java Assignment Operators

 Tutorials  References  Exercises  Get Certified

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO [Link] C

Java Assignment Operators


❮ Previous Next ❯

Assignment Operators
Assignment operators are used to assign values to variables.

In the example below, we use the assignment operator ( = ) to assign the value 10 to a variable
called x:

Example Get your own Java Server

int x = 10;

Try it Yourself »

The addition assignment operator ( += ) adds a value to a variable:

[Link] 1/7
3/12/26, 11:41 AM Java Assignment Operators

 Tutorials 
Example References  Exercises  Get Certified

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO [Link] C
int x = 10;
x += 5;

Try it Yourself »

A list of all assignment operators:

Operator Example Same As Try it

= x=5 x=5 Try it »

+= x += 3 x=x+3 Try it »

-= x -= 3 x=x-3 Try it »

*= x *= 3 x=x*3 Try it »

/= x /= 3 x=x/3 Try it »

%= x %= 3 x=x%3 Try it »

&= x &= 3 x=x&3 Try it »

|= x |= 3 x=x|3 Try it »

^= x ^= 3 x=x^3 Try it »

>>= x >>= 3 x = x >> 3 Try it »

<<= x <<= 3 x = x << 3 Try it »

Note: Most assignment operators are just shorter ways of writing code. For example, x += 5
is the same as x = x + 5 , but shorter and often easier to read.

[Link] 2/7
3/12/26, 11:41 AM Java Assignment Operators

 Tutorials  References  Exercises  Get Certified

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO [Link] C

REMOVE ADS

Real-Life Example: Tracking Savings


Assignment operators can also be used in real-life scenarios. For example, you can use the +=
operator to keep track of savings when you add money to an account:

Example

int savings = 100;


savings += 50; // add 50 to savings
[Link]("Total savings: " + savings);

Try it Yourself »

❮ Previous Next ❯

XP 10 • 🔥 2 days
[Link] 3/7
3/12/26, 11:41 AM Java Assignment Operators

 Tutorials  References  Exercises  Get Certified

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO [Link] C

COLOR PICKER

 
REMOVE ADS
Python - Assign Multiple Values to Vari…

[Link] 4/7
3/12/26, 11:41 AM Java Assignment Operators

 Tutorials  References  Exercises  Get Certified

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO [Link] C

-->
 PLUS SPACES

GET CERTIFIED FOR TEACHERS

[Link] 5/7
3/12/26, 11:41 AM Java Assignment Operators

 Tutorials 
BOOTCAMPS
References  Exercises 
CONTACT US
Get Certified

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO [Link] C

Top Tutorials
HTML Tutorial
CSS Tutorial
JavaScript Tutorial
How To Tutorial
SQL Tutorial
Python Tutorial
[Link] Tutorial
Bootstrap Tutorial
PHP Tutorial
Java Tutorial
C++ Tutorial
jQuery Tutorial

Top References
HTML Reference
CSS Reference
JavaScript Reference
SQL Reference
Python Reference
[Link] Reference
Bootstrap Reference
PHP Reference
HTML Colors
Java Reference
AngularJS Reference
jQuery Reference

Top Examples Get Certified


HTML Examples HTML Certificate
CSS Examples CSS Certificate
JavaScript Examples JavaScript Certificate
How To Examples Front End Certificate
SQL Examples SQL Certificate
Python Examples Python Certificate
[Link] Examples PHP Certificate
Bootstrap Examples jQuery Certificate
PHP Examples Java Certificate
Java Examples C++ Certificate
XML Examples C# Certificate
jQuery Examples XML Certificate

    

FORUM ABOUT ACADEMY


W3Schools is optimized for learning and training. Examples might be simplified to improve reading and
learning.
Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full

[Link] 6/7
3/12/26, 11:41 AM Java Assignment Operators
correctness

 of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookies and
Tutorials  References  Exercises 
privacy policy.
Get Certified

HTML
 CSS Copyright 1999-2026 by Refsnes
JAVASCRIPT SQL [Link]
All Rights Reserved.
JAVA W3Schools
PHPis Powered
HOW by [Link].
TO [Link] C

[Link] 7/7

You might also like