
Lastly, Java has many, many more operators, and it’s a good idea to have a list of all the operators as a reference.Įven if Java is your first language, you are likely to learn a few more, and although many popular languages are similar, you are never going to memorize all of the minute differences between them, so a list of operators is handy to have saved as a pdf, or bookmark in your browser. bothTrue is false because a false and true evaluate to false in boolean logic. notEqual is true becuase 4 does not equal 5. One last note on the != and & operators although it’s common to use these operators inside of conditional expressions, it’s also possible to use them when assigning to booleans. Is the same thing as: number = number % 2 More on != and & Operators right now number = 5 (= means "is equal to") That probably sounds confusing… so let’s look at the code. It performs modulus division on a variable with a literal or another variable and returns the result into the variable on the left of the operator. The %= operator is similar to the += operator we looked at earlier.

So 5 % 2 is 1, since 2 goes into 5 twice with a remainder of 1. % is the modulus operator, NOT percent! What it does is divide two numbers and return the “remainder”. To understand the last operator, %=, let’s look at what % means in Java.
#Symbol for does not equal in java code#
insert code to get input from user here. If the compared values are not equal to each other than the expression returns true.Īn example of a program that uses both the & and != operator could be a program that multiplies two numbers but only if they are both non-zero values. The != operator is a comparison operator, also used in conditional expressions. A code example will follow after we look at the != operator. An example of how you might use the & operator in real life is that you only wear your rain coat when it is raining AND you are outside not one or the other but both.

It is used to create conditional expressions such as “if this AND that, then do something”. The & operator is a logical operator called “logical AND”. The increment operator offers the shortest possible way to do this: someVariable++ Logical AND (&) someVariable = someVariable + 1 Īnother short hand for the same thing would be: someVariable += 1 The long hand version of which looks like this (assuming the variable has already been declared and initialized). It is called the increment operator and is commonly used to increment a variable that is being used as a counter. The ++ operator is a special short hand assignment, used to add the value of 1 to a variable.

I thought the quality of my post was good enough to share here, so here it is.
