-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOperators.java
More file actions
66 lines (56 loc) · 2.02 KB
/
Operators.java
File metadata and controls
66 lines (56 loc) · 2.02 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package operators;
// Operators class
public class Operators {
// Main function to demonstrate operators.
public static void main(String[] args) {
// Declare variables
int a = 38, b = 2, isum = 38 + 2, idiff = 38 - 2,
iproduct = 38 * 2, iquot = 38 / 2, iremain = 38 % 2;
String str1 = "Jeremy", str2 = "Gallen";
// Output math
System.out.println("The sum of a and b is: " + isum);
System.out.println("The difference of a and b is: " + idiff);
System.out.println("The product of a and b is: " + iproduct);
System.out.println("The quotient of a and b is: " + iquot);
System.out.println("The remainder of a / b is: " + iremain);
System.out.println("My name is " + str1 + " " + str2 + ".");
// If/else to show which value is greater
if (a > b) {
System.out.println("a is greater than b");
} else {
System.out.println("b is greater than a");
}
// If/else to show which value is lesser
if (a < b) {
System.out.println("a is less than b");
} else {
System.out.println("b is less than a");
}
// If/else to show if values are equal
if (a == b) {
System.out.println("a and b are equal");
} else {
System.out.println("a and b are unequal");
}
// If/else to show if values are unequal
if (a != b) {
System.out.println("a and b are unequal");
} else {
System.out.println("a and b are equal");
}
// If/else to demonstrate && operator
if (a > b && isum < idiff) {
System.out.println("a is greater than b and their sum is less than their difference");
} else {
System.out.println("both conditions have not been satisfied");
}
// If/else to demonstrate || operator
if (a < b || isum > idiff) {
System.out.println("a is less than b or their sum is greater than their difference");
} else {
System.out.println("neither or condition has been satisfied");
}
// Ternary operator demonstration
System.out.println(a >= b ? "a is greater than b" : "a is not greater than b");
}
}