ARITHMETIC OPERATORS IN JAVA
Operator Description
Addition operator
+
(also used for String concatenation)
Subtraction operator
* Multiplication operator
/ Division operator
% Modulus operator (gets the remainder)
Increment Operator-
++ Pre-Increment- a variable will be added by 1 before current statement is executed
Post Increment- a variable will be added by 1 after the current statement is executed
Decrement Operator-
Pre-Decrement- a variable will be decreased by 1 before current statement is executed
Post-Decrement- a variable will be decreased by 1 after the current statement is executed
Example:
Name: ________________________________________ Class Sched: ________________
IT112 Jay Anthony R. Nuñez
Fundamentals in Programming Instructor
Activity #2 – Arithmetic Operations
Self-Paced Learning
Try and test the following codes/statements provided for each item. Explain what you have noticed with the
process or output after each example. If error occurs, determine and explain the cause/s.
# CODE / STATEMENTS CONCLUSION
int num1=1, num2=2;
int sum=num1+num2;
1 System.out.println("Result 1:"+sum+5);
System.out.println("Result 2:"+(sum+5));
System.out.println("Result 3:"+sum);
int num1=1;
double num2=2;
2 double quotient=num1/num2;
System.out.print("Result 1:"+quotient);
int num1=1;
int num2=2;
int quotient1=num1/num2;
3 double quotient2=num1/num2;
System.out.println("Result 1:"+quotient1);
System.out.println("Result 2:"+quotient2);
double num1=1;
double num2=2;
4 int quotient=num1/num2;
System.out.print("Result 1:"+quotient);
int num=5;
num++;
System.out.println("Result 1:"+num);
--num;
System.out.println("Result 2:"+num);
5
num=num+1;
System.out.print("Result 3:"+num);
num+1;
System.out.print("Result 4:"+num);
*Pass this activity sheet only.
IT112 Jay Anthony R. Nuñez
Fundamentals in Programming Instructor