Page 33 - CTS - CSA TP - Volume 2
P. 33
COMPUTER SOFTWARE APPLICATION - CITS
3 Arithmetic Operations:
• The expression 10 * 10 / 5 + 3 - 1 * 4 / 2 involves multiplication (*), division (/), addition (+),and subtraction
(-) operations.
4 Step-by-Step Evaluation:
10 * 10 / 5 + 3 - 1 * 4 / 2
• Multiply: 100 / 5 + 3 - 1 * 4 / 2
• Divide: 20 + 3 - 1 * 4 / 2
• Multiply: 20 + 3 - 4 / 2
• Divide: 20 + 3 - 2
• Add: 23 - 2
• Subtract: 21
Output:
TASK 6: Java Left Shift Operator Example
public class OperatorExample6{
public static void main(String args[]){
System.out.println(10<<2);//10*2^2=10*4=40
System.out.println(10<<3);//10*2^3=10*8=80
System.out.println(20<<2);//20*2^2=20*4=80
System.out.println(15<<4);//15*2^4=15*16=240
}}
Explanation:
1 Left Shift Operator (<<):
• The left shift operator (<<) shifts the bits of a binary number to the left by a specified number of positions.
• The general form is value << numBits, where value is the number to be shifted, and num Bits is the number
of positions to shift.
2 Bitwise Left Shift Operations:
• The program performs left shift operations on various integers.
3 Examples:
• System.out.println(10 << 2);
• Left shift the binary representation of 10 by 2 positions.
• 10 in binary is 1010. After left shifting by 2, it becomes 101000, which is 40 in decimal.
• Output: 40
18
CITS : IT & ITES - Computer Software Application - Exercise 82