June 2018
Beginner
722 pages
18h 47m
English
The best way to understand operators is to see them in action. Here is our demo application code (with results captured in comments) that explains the unary operators + and -:
public class Ch09DemoApp { public static void main(String[] args) { int i = 2; //unary "+" is assumed by default int x = -i; //unary "-" makes positive become negative System.out.println(x); //prints: -2 int y = -x; //unary "-" makes negative become positive System.out.println(y); //prints: 2 }}
And the following code demonstrates the binary operators +, -, *, /, and %:
int z = x + y; //binary "+" means "add"System.out.println(z); //prints: 0z = x - y; //binary "-" means "subtract"System.out.println(z) ...
Read now
Unlock full access