Arithmetic and Unary Operators

Submitted by: 
Language: 

Introduction:
Hello, this page will teach you about another two types of Operators in Java, Arithmetic and Unary.

Arithmetic Operators - What are they?
Arithmetic Operators are symbols used to perform a mathematical sum. There are five types of these:

+ Add
- Subtract
/ Division
* Multiplication
% Modular/Remainder

All of these operators have clear uses for anyone with basic knowledge of Math.

Unary Operators - What are they?
Unary Operators are used to manipulate a number value - at least, that's what I say. Again, there are five types of Unary Operators:

+ Indicates Positive Value
- Negates An Expression
++ Increments Value by 1
-- Decrements Value by 1
! Inverts Boolean Value

Examples:
Here is an example of how Arithmetic Operators are used:

  1. int tutorial = 2;
  2. System.out.println(tutorial);
  3. tutorial = tutorial + 1;
  4. System.out.println(tutorial);
  5. tutorial = tutorial - 2;
  6. System.out.println(tutorial);
  7. tutorial = tutorial * 50;
  8. System.out.println(tutorial);
  9. tutorial = tutorial / 3;
  10. System.out.println(tutorial);
  11. tutorial = tutorial % 10;
  12. System.out.println(tutorial);

which gives the output:

2
3
1
50
16
6

And here is an example of how to use Unary Operators:

  1. int tut = 2;
  2. System.out.println(tut);
  3. tut++;
  4. System.out.println(tut);
  5. tut--;
  6. boolean opposite = false;
  7. if (!opposite){
  8. System.out.println(tut);
  9. }

Which gives the output:

2
3
2

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.