Professional Documents
Culture Documents
Group Name Class F1T2 F3T2 K1T2 Date: Kitkat Lollipop Marshmallow Nougat Oreo
Group Name Class F1T2 F3T2 K1T2 Date: Kitkat Lollipop Marshmallow Nougat Oreo
1.
(a) Trace the output.
int a = 12, b = 5;
// addition operator
System.out.println("a + b = " + (a + b));
// subtraction operator
System.out.println("a - b = " + (a - b));
// multiplication operator
System.out.println("a * b = " + (a * b));
// division operator
System.out.println("a / b = " + (a / b));
// modulus operator
System.out.println("a % b = " + (a % b));
a + b = 17
a-b=7
a * b = 60
a/b=2
a%b=2
1|
UNIT SAINS KOMPUTER
KOLEJ MATRIKULASI MELAKA
SESSION 2018/2019
(x < y) Relational
(x && y) Logical
x == y Relational
2|
UNIT SAINS KOMPUTER
KOLEJ MATRIKULASI MELAKA
LECTURE QUESTIONS
3.0: JAVA LANGUAGE
3.2 : DATA TYPE, OPERATOR AND EXPRESSIONS
1.
(a) Examine the following Java segment code and give the output.
int i = 8, j = 5, k;
double z;
k = 3 * ((8/5) + 8 % 11))
= 27
(ii) z = 2 * i / 5 + 4 * j – 3 % i + j – 2;
z=2*8/5+4*5–3%8+5–2
= 23.2
(ii) int a = 5 + 7 % 2;
System.out.println (a);
6
3|
UNIT SAINS KOMPUTER
KOLEJ MATRIKULASI MELAKA
2.
(a) Assuming x is 5, y is 6, and z is 8, indicate whether each of the following relational
expressions is true or false:
int a = 20;
int b = 10;
int c = 15;
int d = 5;
int e;
e = (a + b) * c / d;
System.out.println (“Value of (a + b) * c / d is : “ + e;
e = ((a + b) * c) / d;
System.out.println (“Value of ((a + b) * c) / d is : “ + e;
e = (a + b) * (c / d);
System.out.println (“Value of (a + b) * (c / d) is : “ + e;
e = a + (b * c) / d;
System.out.println (“Value of a + (b * c) / d is : “ + e;
Value of (a + b) * c / d is : 90
Value of ((a + b) * c) / d is :90
Value of (a + b) * (c / d) is : 90
Value of a + (b * c) / d is : 50
4|
UNIT SAINS KOMPUTER
KOLEJ MATRIKULASI MELAKA
(ii) What is the output for the following Java program segment?
int a = 5, b = 10;
int c;
c = a * 2 + b;
System.out.println (“c = “ + c );
c = 20
(iii) What is the output for the following Java program segment?
int a = 5, b = 10;
int c;
c = a * 2 + b/2;
System.out.println (“c = “ + c );
c = 15
int a = 5, b = 10;
int c;
c = ((a*2)+(b/2));
System.out.println (“c = “ + c );
C= 15
(v) What is the output for the following Java program segment?
int a = 7 * 3 + 24 / 3 - 5;
int b = (7 * 3) + (24 / 3) - 5;
int z;
z = a + b;
System.out.println (“value of a = “ + a );
System.out.println (“value of b = “ + b );
System.out.println (“value of z = “ + z );
value of a= 24
value of b=24
value of z=48
5|
UNIT SAINS KOMPUTER
KOLEJ MATRIKULASI MELAKA
SESSION 2018/2019
Learning Outcome (CLO1)
(f) Determine the operator precedence and associativity of operators.
c = 12.9
y = 10.0
SESSION 2019/2020
Learning Outcome (CLO1)
(f) Determine the operator precedence and associativity of operators.
true
(ii) (6 % 4) % 5 ;
12
[END OF QUESTIONS]
6|