Assignment + Equality and Relational Operators

Submitted by: 
Language: 

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

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You may insert videos with [video:URL]
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3> <iframe> [video]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.