-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOperators_05.java
More file actions
104 lines (64 loc) · 3.18 KB
/
Copy pathOperators_05.java
File metadata and controls
104 lines (64 loc) · 3.18 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package Java_practice;
public class Operators_05 {
public static void main (String args[]) {
System.out.println("************************************************");
float a=12; // Reasons for using float is "we never know when floating value will occur"
float b=34;
System.out.println("a=" +a);
System.out.println("b=" +b);
System.out.println("************************************************");
System.out.println("Airthematic Operators");
float sum=a+b;
float substraction=a-b;
float multiplication=a*b;
float dividation=a/b;
float percentage=a%b;
System.out.println("addition of " +a+ " and " +b+ " is " +sum);
System.out.println("substraction of " +a+ " and " +b+ " is " +substraction);
System.out.println("multiplication of " +a+ " and " +b+ " is " +multiplication);
System.out.println("dividation of " +a+ " and " +b+ " is " +dividation);
System.out.println("percentage of " +a+ " and " +b+ " is " +percentage);
System.out.println("************************************************");
System.out.println("Assignment Operators");
float a1= a-= b ; //its like a=a-b
float a2= a += b ; //its like a=b
float a3= a *= b ; //a=a*b
float a4= a /= b ; // a=a/b
System.out.println("a-= b is "+a1);
System.out.println("a += b is "+a2);
System.out.println("a *= b is "+a3);
System.out.println("b /= b is "+a4);
System.out.println("************************************************");
System.out.println("Comparison Operators");
boolean c1 = a==b;
boolean c2 = a!=b;
boolean c3 = a<b;
boolean c4 = a>b;
System.out.println("a==b is " +c1);
System.out.println("a!=b is " +c2);
System.out.println("a<b is " +c3);
System.out.println("a>b is " +c4);
System.out.println("Logical Operators");
boolean l1 = a==b && a!=b; // if one the true and one is false it will consider as false
boolean l2 = a<b || a>b; // if one the true and one is false it will consider as true
System.out.println("a==b && a!=b is " +l1);
System.out.println("a<b || a>b is " +l2);
System.out.println("************|Ends Here|**********");
System.out.println("Precedence of Associativity between Operators");
int x1= 40 * 50 / 10;
int x2= 100 / 20 * 10;
System.out.println("40 * 8 / 47 is " +x1);
System.out.println("40 / 20 * 10 is " +x2);
System.out.println("************|Ends Here|**********");
System.out.println("Increment and decrement Operators");
int x= 50;
System.out.println("Value of x Is " +x);
int y=x++; // It stores the value of x into y and then increment it
System.out.println("Value of y=x++ Is " +y+ " And x is now " +x);
int z=++x;
System.out.println("Value of z=++x; Is " +z+ " And x is now " +x);
int w=--x;
System.out.println("Value of w=--x; Is " +w+ " And x is now " +x);
System.out.println("************|Ends Here|**********");
}
}