Page 318 - CITS - Computer Software Application -TT
P. 318
COMPUTER SOFTWARE APPLICATION - CITS
Examples of Operator
public class OperatorDemo {
public static void main(String[] args) {
// Arithmetic operators
int num1 = 10;
int num2 = 5;
int sum = num1 + num2;
int difference = num1 - num2;
int product = num1 * num2;
int quotient = num1 / num2;
int remainder = num1 % num2;
System.out.println(“Arithmetic Operators:”);
System.out.println(“Sum: “ + sum);
System.out.println(“Difference: “ + difference);
System.out.println(“Product: “ + product);
System.out.println(“Quotient: “ + quotient);
System.out.println(“Remainder: “ + remainder);
// Assignment operators
int x = 5;
x += 3; // Equivalent to x = x + 3
System.out.println(“\nAssignment Operators:”);
System.out.println(“x after assignment: “ + x);
// Relational operators
int a = 10; int b = 20;
boolean isEqual = (a == b);
boolean isNotEqual = (a != b);
boolean isGreater = (a > b);
boolean isLess = (a < b);
System.out.println(“\nRelational Operators:”);
System.out.println(“Is equal: “ + isEqual);
System.out.println(“Is not equal: “ + isNotEqual);
System.out.println(“Is greater: “ + isGreater);
System.out.println(“Is less: “ + isLess);
// Logical operators
boolean p = true;
boolean q = false;
305
CITS : IT&ITES - Computer Software Application - Lesson 78 - 84
78