25.02.2017 Views

java_tutorial

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Java<br />

9<br />

&=<br />

Bitwise AND assignment operator.<br />

Example: C &= 2 is same as C = C & 2<br />

10<br />

^=<br />

bitwise exclusive OR and assignment operator.<br />

Example: C ^= 2 is same as C = C ^ 2<br />

11<br />

|=<br />

bitwise inclusive OR and assignment operator.<br />

Example: C |= 2 is same as C = C | 2<br />

Example<br />

The following program is a simple example that demonstrates the assignment operators.<br />

Copy and paste the following Java program in Test.<strong>java</strong> file. Compile and run this program:<br />

public class Test {<br />

public static void main(String args[]) {<br />

int a = 10;<br />

int b = 20;<br />

int c = 0;<br />

c = a + b;<br />

System.out.println("c = a + b = " + c );<br />

c += a ;<br />

System.out.println("c += a = " + c );<br />

c -= a ;<br />

System.out.println("c -= a = " + c );<br />

c *= a ;<br />

System.out.println("c *= a = " + c );<br />

55

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!