Basic Java Language: Difference between revisions

wikademia>Digitalme
m Reverted edits by 70.114.155.220 (Talk) to last version by Crossbow9 using Rollback
wikademia>Crossbow9
Line 77: Line 77:


==Operators==
==Operators==
===Equality Operator = ===
===Assignment Operator = ===
The equality operator sets the variable on its left equal to the value on its right. This code creates the variable ''a'' and sets it equal to 5
The assignment operator sets the variable on its left equal to the value on its right. This code creates the variable ''a'' and sets it equal to 5
<pre>int a;
<pre>int a;
a = 5;</pre>
a = 5;</pre>
Line 85: Line 85:
int b;
int b;
b = 6;
b = 6;
a = b;</pre>
a = b; //a equals 6</pre>
At first glance, you might think that the last statement is setting ''a'' equal to the letter "b", but instead it is setting ''a'' equal to the ''value'' of ''b'', which is 6.
At first glance, you might think that the last statement is setting ''a'' equal to the letter "b", but instead it is setting ''a'' equal to the ''value'' of ''b'', which is 6.
===Addition Operator +===
Unlike the = operator, a statement that simply uses the addition operator and two other values on either side does not do anything significant. For example, neither of the following three lines of code do anything.
<pre>5 + 6;
a + 9
a + b </pre>
If you want to you want to use the addition operator to add 6 to the value of ''a'', it would be used like this:
</pre>a = a + 6;</pre>
===Subtraction -, Division / and Multiplication * Operators===


'''More comming soon'''
'''More comming soon'''


[[Topic:Java|Back to Java Main Page]]
[[Topic:Java|Back to Java Main Page]]