Page 339 - Computer_Science_F5
P. 339
Computer Science Program Example 5.6:
Java program to demonstrate arithmetic operators
public class Operators {
FOR ONLINE READING ONLY
public static void main(String[] args) {
int a = 12, b = 23, c = 0, d = 33, e = 10, f = 50;
String x = “Welcome Java”, y = “Tujifunze”;
System.out.println(“a + b = “+(a + b));
System.out.println(“a - b = “+(a - b));
System.out.println(“x + y = “+x + y);
System.out.println(“a * b = “+(a * b));
System.out.println(“a / b = “+(a / b));
System.out.println(“a % b = “+(a % b));
}
}
Output:
Figure 5.8: Arithmetic operator
(b) Relational operators
This include comparison: <, >, <=, >=, instanceof and Equality: ==, != . Table 5.8
shows the Relational operators that are supported by Java language.
330
for Advanced Secondary Schools
Computer Science Form 5.indd 330 23/07/2024 12:34

