32 OPERATORS, OPERANDS AND EXPRESSIONS
//OPERATORS
int myVar = 15 +2;
+--->operator
15 & 12 are operands
//EXPRESSION
15+12 is the expression which returns 27
package com.cnc;
public class Main {
public static void main(String[] args) {
int result = 1 + 2; // 1 + 2 = 3
System.out.println("1 + 2 = "+result);
int previousResult = result;
System.out.println("previousRESULT = "+previousResult);
result = result -1; // 3 - 1 = 2
System.out.println("3 -1 = "+result);
System.out.println("previousRESULT = "+previousResult);
result = result*10; // 2 * 10 = 20
System.out.println("2 * 10 = "+result);
result = result/5; // 20 / 5 = 4
System.out.println("20 / 5 = "+result );
result = result % 3; // remainder of (4 % 3) = 1
System.out.println("4 % 3 = "+result);
//ABBREVIATING OPERATORS //result = result + 1
result++; // 1+1=2
System.out.println("1 + 1 = "+result);
result--;// 2-1 = 1
System.out.println("2 - 1 = "+result);
//result = result +2
result +=2; // 1 + 2 = 3
System.out.println("1 + 2 = "+result);
//result = result * 10
result *= 10; // 3 * 10 = 30
System.out.println("3 * 10 ="+result);
//result = result/3
result /= 3;
System.out.println("result / 3 = "+result);
//result = result - 2
result -=2; // 10 - 2 = 8
System.out.println(result);
}
}
OUTCOME
1 + 2 = 3
previousRESULT = 3
3 -1 = 2
previousRESULT = 3
2 * 10 = 20
20 / 5 = 4
4 % 3 = 1
1 + 1 = 2
2 - 1 = 1
1 + 2 = 3
3 * 10 =30
result / 3 = 10
8