-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOperators.java
More file actions
48 lines (40 loc) · 1.98 KB
/
Operators.java
File metadata and controls
48 lines (40 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
public class Operators{
public static void main(String[] args){
//Assignment operator(=)
int num1 = 13;
int num2 = 5;
//Aritmetic operator(+,*,-,/,%)
int sum = num1 + num2; //13 + 5 is 18
int product = num1 * num2;
int difference = num1 - num2;
double quotient = (double)num1 / num2;
int remainder = num1 % num2;
//Relational Operator(>,<,>=,<=,==,!=)
boolean isLessThan = num1 < num2;
boolean isGreaterThan = num1 > num2;
boolean isGreaterThanorEqualTo = num1 >= num2;
boolean isLessThanOrEqualTo = num1 <= num2;
boolean isEqualTo = num1 == num2;
boolean isNotEqualTo = num1 != num2;
//Logical Operator(&&,||, !)
boolean isANDOperator = num1 > num2 && num1 >= num2;
boolean isOrOperator = num1 == num2 || num1 > num2;
boolean isNotOperator = !(num1 == num2 || num1 > num2);
System.out.printf("The sum of the numbers is %d%n", sum);
System.out.printf("The product of the numbers is %d%n", product);
System.out.printf("The difference of the numbers %d and %d is %d%n", num1, num2,difference);
System.out.printf("The quotient is %.1f%n", quotient);
System.out.printf("The remainder is %d%n", remainder);
System.out.println("=====================================================");
System.out.printf("The %d < %d ? %b%n", num1,num2,isLessThan);
System.out.printf("The %d >= %d ? %b%n", num1,num2,isGreaterThan);
System.out.printf("The %d >= %d ? %b%n", num1,num2,isGreaterThanorEqualTo);
System.out.printf("The %d >= %d ? %b%n", num1,num2,isLessThanOrEqualTo);
System.out.printf("The %d == %d ? %b%n", num1,num2,isEqualTo);
System.out.printf("The %d != %d ? %b%n", num1,num2,isNotEqualTo);
System.out.println("=====================================================");
System.out.printf("Is %d > %d && %d >= %d? %b%n", num1,num2,num1,num2,isANDOperator);
System.out.printf("Is %d == %d || %d > %d? %b%n", num1,num2,num1,num2,isOrOperator);
System.out.printf("Is !(%d == %d || %d > %d)? %b%n", num1,num2,num1,num2,isNotOperator);
}
}