Assignment + Equality and Relational Operators

Introduction: Welcome! This page will teach you about Equality and Relational Operators as well as the Assignment Operator. What is an Operator? Operators within Java are signs used to manipulate a variable. Depending on what type of Operator is in use will determine the outcome. What is an Equality and Relational Operator? Equality and Relational Operators are used to check if a variable is a value. You can use one of these operators to check if the value of a variable is the exact same as another value or if it is within a range of values (see example below). What is an Assignment Operator? Unlike Equality and Relational Operators, there is only one operator for the "Assignment Operators" category. The only sign used for assignment is a single equals sign. All Operators List: Here is a list of all possible Equality and Relational Operators as well as the single Assignment Operator... Assignment Operator:
= set equal to
Equality and Relational Operators:
== equal to
!= not equal to
> greater than
>= greater than or equal to
< less than
<= less than or equal to
Example: Here is an example of setting a new variable integer named "ch" equal to 5, then checking if its; equal to 3, greater than 3 or less than 3.
  1. int ch = 3;
  2. if (ch == 3){
  3. System.out.println("Ch is 3!");
  4. }else if (ch > 3){
  5. System.out.println("Ch is greater than 3!");
  6. }else if (ch < 3){
  7. System.out.println("Ch is less than 3!");
  8. }
Finished!

Add new comment