Week003 - Operator: Laboratory Exercise 003
Week003 - Operator: Laboratory Exercise 003
1
Operators
Week003 - Operator
Laboratory Exercise 003
Objective/s:
At the end of this activity, you should be able to:
Write and evaluate expressions to compute values
Write program using different operations
Understand and use the different kind of operators in a java program.
Procedure:
1. Write a java program named JavaOperators and print the results of the following
expressions:
a. 30 / 5
b. 12.0/5
c. 10/5-8/2
d. 34*12 + 15*33
e. 42%2 + 1%16
B:
6 2.4 -2 93 23
C: syntax error
D:
Assessments
30 / 5
12.0/5
10/5-8/2
34*12 + 15*33
42%2 + 1%16
B: 2
C: 1
D: 0
3. Try to correct the lines with error by providing the correct data type, save and recompile.
B: 10
1
0
C: 5+5
5/5
Computer Programming 2
3
Operators
5-5
D: nothing shows
4. Open the file that you have created and add the following codes in your main method:
int x = 0;
int y = 2;
int z = 4;
System.out.println(++x);
System.out.println(x++);
System.out.println(z % x);
System.out.println(x >> y);
C: 1
D: 0
C: 1
D: 0
C: 1
D: 0
Assessments
System.out.println(x >> y);? B: 2
C: 1
D: 0
C: 1
D: 0
C: 1
D: 0
C: 1
D: 0
Create a NetBeans project for problem no. 6 below. The project name should be as
follows:
Project Name: Lab003_<lastname_firstname>
Example: Lab003_Blanco_Maria
Computer Programming 2
5
Operators
6. Write a program that will declare and initialize 2 integer variables. The program should
compute the sum, difference, product, quotient (first integer/second integer) and
average of the 2 integers. It should also determine the maximum (higher value) and
the minimum (smaller value) between the two. Use the ? operator to implement the
maximum and minimum value.
Sample Output:
First Integer: 25
Second Integer: 3
Sum: 28
Difference: 22
Product: 75
Quotient: 8.333333333333334
Average: 14.0
Max integer: 25
Min integer: 3
Assessments