-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExampleOperators.java
More file actions
68 lines (53 loc) · 1.63 KB
/
ExampleOperators.java
File metadata and controls
68 lines (53 loc) · 1.63 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
package com.tyss.corejava;
public class ExampleOperators {
public static void main(String[] args) {
//unary operator
int a=10;
System.out.println("unary operator");
System.out.println("a");
System.out.println(a++);
System.out.println(++a);
System.out.println(a--);
//arithmetic operator
int b=20;
System.out.println("arithmetic operator");
System.out.println(a+b);
System.out.println(a-b);
System.out.println(a*b);
System.out.println(a/b);
System.out.println(a%b);
//relational operator
System.out.println("relational operator");
System.out.println(a>b);
System.out.println(a<b);
System.out.println(a>=b);
System.out.println(a<=b);
System.out.println(a==b);
System.out.println(a!=b);
//Logical operator
System.out.println("Logical operator");
int c=40;
System.out.println(c<a && c<b);
System.out.println(c>a || c<b);
//Circuit break
/*
and -> if anyone false it return false and the next conditions are not executed
are -> if anyone true it return true and the next conditions are not executed*/
System.out.println("circuit break");
System.out.println(a>b && ++c>b);
System.out.println(a++<b || ++c<b);
System.out.println(a++<b || ++c<b++);
System.out.println(a);
System.out.println(b);
System.out.println(c);
//Bitwise operator
System.out.println("Bitwise operators");
System.out.println(2|10);
System.out.println(4|10);
//ternary operator
System.out.println("ternary operator");
int x=10;
String restriction=(x<18)?("not eligible for voting"):("eligible for voting");
System.out.println(restriction);
}
}