Docsity

Laboratory Exercise 003: Java Operators for Computer Programming 2, Cheat Sheet of Computer Science

Toggle sidebar
bg1
Computer Programming 2
Operators 1
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.
What to Prepare for the Activity:
NetBeans IDE 8.2 which could be downloaded from
https://netbeans.org/downloads /
Java Standard Edition (SE) Development Kit 8 (JDK8).
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
Test Stem / Question Choices
1: What is the result? A:
6
2.4
-2
903
1
B:
6 2.4 -2 93 23
C: syntax error
Assessments
pf3
pf4
pf5

Partial preview of the text

Download Laboratory Exercise 003: Java Operators for Computer Programming 2 and more Cheat Sheet Computer Science in PDF only on Docsity!

Computer Programming 2 Operators 1

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.

What to Prepare for the Activity:

 NetBeans IDE 8.2 which could be downloaded from https://netbeans.org/downloads/  Java Standard Edition (SE) Development Kit 8 (JDK8).

Procedure:

  1. Write a java program named JavaOperators and print the results of the following expressions: a. 30 / 5 b. 12.0/ c. 10/5-8/ d. 3412 + 15 e. 42%2 + 1%

Test Stem / Question Choices

1: What is the result? A: 6

903 1 B: 6 2.4 -2 93 23 C: syntax error Assessments

D: 30 / 5 12.0/ 10/5-8/ 3412 + 15 42%2 + 1%

  1. Now add the following: a. “five ” + 5 b. “5” / c. 5 – “5”

Test Stem / Question Choices

2: How many errors are there? A: 3 B: 2 C: 1 D: 0

  1. Try to correct the lines with error by providing the correct data type, save and recompile.

Test Stem / Question Choices

3: What is the result? A: five + 5 1 0 B: 10 1 0 C: 5+

7: What is the output of this statement System.out.println(x >> y);? A: 3 B: 2 C: 1 D: 0

  1. Add also the following codes in your main method: boolean a; boolean b = true; System.out.println(a && b); System.out.println(a || b); System.out.println(b? a : b); c. Save the file. d. Compile and run the program.

Test Stem / Question Choices

8: What is the output of this statement System.out.println(a && b);? A: true B: false C: 1 D: 0 9: What is the output of this statement System.out.println(a || b);? A: true B: false C: 1 D: 0 10: What is the output of this statement System.out.println(b? a : b);? A: true B: false C: 1 D: 0  Create a NetBeans project for problem no. 6 below. The project name should be as follows:

Computer Programming 2 Operators 5 Project Name: Lab003_<lastname_firstname> Example: Lab003_Blanco_Maria  The Java filename for No. 5 should be MaxAndMin.java  Compress the NetBeans project into .rar or .zip format.  Only NetBeans project compressed in .rar or .zip format will be accepted.

  1. 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. Average: 14. Max integer: 25 Min integer: 3 Assessments