Java Operators
Java Tutorial » Java Operators
Operators as : sum, multiplied, decrease , etc... are used to perform operations on variables and values.
In the below example, we use sum, multiplied, decrease and division operator to see how it is working:
Example:
150
500
5
2
public class Main {
public static void main(String[] args) {
int x = 100 + 50; // sum
int y = 10 * 50; // multiplied
int z = 10 - 5; // decrease
int w = 10 / 5; // division
System.out.println(x);
System.out.println(y);
System.out.println(z);
System.out.println(w);
}
}
Output:public static void main(String[] args) {
int x = 100 + 50; // sum
int y = 10 * 50; // multiplied
int z = 10 - 5; // decrease
int w = 10 / 5; // division
System.out.println(x);
System.out.println(y);
System.out.println(z);
System.out.println(w);
}
}
150
500
5
2
Arithmetic Operators
For variable X holds 15 and variable Y holds 25,
+ (Addition) Adds values. X + Y will give 40
- (Subtraction) Subtracts one value from another. X - Y will give -10
* (Multiplication) Multiplies values. X * Y will give 375
/ (Division) Divides one value by another. Y / X will give 1
% (Modulus) Returns the division remainder. Y % X will give 10
++ (Increment) Increases the value of operand by 1. X++ gives 16
-- (Decrement) Decreases the value of operand by 1. X-- gives 14
Example: assign value
System.out.println(z);
System.out.println(w);
System.out.println(t);
System.out.println(s); }
}
Output:
24
43
23
400
3
public class Main {
public static void main(String[] args) {
int y = 24;
//adds a value to a variable
int z = 33;
z +=10 ;
//Subtract a value to a variable
int w = 33;
w -=10 ;
//Multiplay
int t = 40;
t *=10 ;
//Divide
int s = 33;
s /=11 ;
//
System.out.println(z);
System.out.println(w);
System.out.println(t);
System.out.println(s); }
}
24
43
23
400
3
Java Comparison Operators
Comparison operators java are used to compare two values:
Example:
false
true
true
false
true
false
public class Main {
public static void main(String[] args) {
int z = 14;
int w = 7;
System.out.println(z == w); // Equal to - false because 14 is not equal to 7
System.out.println(z != w); // Not equal - true because 14 is not equal to 7
System.out.println(z > w); // Greater than - true because 14 is greater than 7
System.out.println(z < w); // Less than - false because 14 is not less than 7
System.out.println(z >= w); // Greater than or equal to - true because 14 is greater, or equal,to 7
System.out.println(z <= w); // Less than or equal to - false because 14 is neither less than or equal to 7
}
}
Output:public static void main(String[] args) {
int z = 14;
int w = 7;
System.out.println(z == w); // Equal to - false because 14 is not equal to 7
System.out.println(z != w); // Not equal - true because 14 is not equal to 7
System.out.println(z > w); // Greater than - true because 14 is greater than 7
System.out.println(z < w); // Less than - false because 14 is not less than 7
System.out.println(z >= w); // Greater than or equal to - true because 14 is greater, or equal,to 7
System.out.println(z <= w); // Less than or equal to - false because 14 is neither less than or equal to 7
}
}
false
true
true
false
true
false
Java Operators list, oder of precedence, overloading, table, precedence table, overloaded for string objects, exercises, example
Java Operators - java
Online Editor
This tool makes it easy to create, adjust, and experiment with custom colors for the web.
HTML Templates

Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.
CSS HTML Layout

Find here examples of creative and unique website layouts.
Free CSS HTML Menu

Find here examples of creative and unique website CSS HTML menu.