Java Fundamentals
Allow nothing or no one to slow your pace or affect your energy; stay consistently flowing, forever growing.
Subject: Java Fundamentals
Output:
valAddA + valAddB: 3.0
valSubA - valSubB: 1.0
valMulA * valMulB: 8.0
ValDivA / ValDivB: 2.6
valModA % valModB: 3.0
valAddAB + valAddBA: 3
valSubAB - valSubBA: 1.0
valMulAB * valMulBA: 8
ValDivAB / ValDivBA: 2
valModAB % valModBA: 3
Subject: Java Fundamentals
Topics:
- Arithmetic Operators
- Basic Operators: + - * / %
- Prefix/Post fix Operators: ++ --
- Compound/Assignment Operators: += -= /= *= %=
- Basic Operators Example:
public class BasicOperators {
public static void main(String[] args) {
/**
* Floating Point Examples
*/
//Addition of two variables
float valAddA = 1.0f;
float valAddB = 2.0f;
System.out.println("valAddA + valAddB: " + (valAddA + valAddB));
//Subtraction of two variables
float valSubA = 5.0f;
float valSubB = 4.0f;
System.out.println("valSubA - valSubB: " + (valSubA - valSubB));
//Multiplication of two variables
float valMulA = 4.0f;
float valMulB = 2.0f;
System.out.println("valMulA * valMulB: " + (valMulA * valMulB));
//Division of two variables
float valDivA = 13.0f;
float valDivB = 5.0f;
System.out.println("ValDivA / ValDivB: " + (valDivA / valDivB));
//Modulus of two variables
float valModA = 13.0f;
float valModB = 5.0f;
System.out.println("valModA % valModB: " + (valModA % valModB));
/**
* Integer Examples
*/
//Addition of two variables
int valAddAB = 1;
int valAddBA = 2;
System.out.println("valAddAB + valAddBA: " + (valAddAB + valAddBA));
//Subtraction of two variables
float valSubAB = 5;
float valSubBA = 4;
System.out.println("valSubAB - valSubBA: " + (valSubAB - valSubBA));
//Multiplication of two variables
int valMulAB = 4;
int valMulBA = 2;
System.out.println("valMulAB * valMulBA: " + (valMulAB * valMulBA));
//Division of two variables
int valDivAB = 13;
int valDivBA = 5;
System.out.println("ValDivAB / ValDivBA: " + (valDivAB / valDivBA));
//Modulus of two variables
int valModAB = 13;
int valModBA = 5;
System.out.println("valModAB % valModBA: " + (valModAB % valModBA));
}
}
valAddA + valAddB: 3.0
valSubA - valSubB: 1.0
valMulA * valMulB: 8.0
ValDivA / ValDivB: 2.6
valModA % valModB: 3.0
valAddAB + valAddBA: 3
valSubAB - valSubBA: 1.0
valMulAB * valMulBA: 8
ValDivAB / ValDivBA: 2
valModAB % valModBA: 3