-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComplementTable.java
More file actions
158 lines (144 loc) · 3.22 KB
/
Copy pathComplementTable.java
File metadata and controls
158 lines (144 loc) · 3.22 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
// Try this: 2-2: 6. On your own, try modifying the program so that it uses and displays 1's and 0's, rather than
// true and false.
public class ComplementTable {
/*
* public void println() \ Terminates the current line by writing the line
* separator string. The line separator string is defined by the system property
* line.separator, and is not necessarily a single newline character ('\n').
*
* public void println(boolean x) \ Prints a boolean and then terminate the
* line. This method behaves as though it invokes print(boolean) and then
* println().
*
* Reference:
* https://docs.oracle.com/en/java/javase/13/docs/api/java.base/java/io/
* PrintStream.html#println(char%5B%5D)
*/
/*
* java line separator explained:
*
* public static String lineSeparator() on Windows systems, it returns “\r\n” or
* a positive integer.
*
* Reference:
* https://www.geeksforgeeks.org/system-lineseparator-method-in-java-with-
* examples/
*/
/*
* “\r” stands for "carriage return" on the textbook page 74.
*
* Carriage return is the key on a computer keyboard that you press in order to
* move down a line on the screen, or to mark the end of a section of text or
* data, or the act of pressing this key.
*
* Reference:
* https://dictionary.cambridge.org/dictionary/english/carriage-return
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
// System.out.print("P\tQ\tAND\tOR\tXOR\tNOT");
// System.out.print("P\tQ\tAND\tOR\tXOR\tNOT\n");
System.out.println("P\tQ\tAND\tOR\tXOR\tNOT");
boolean p, q;
p = true;
q = true;
System.out.print("1\t1\t");
if (p & q) {
System.out.print("1\t");
} else {
System.out.print("0\t");
}
if (p | q) {
System.out.print("1\t");
} else {
System.out.print("0\t");
}
if (p ^ q) {
System.out.print("1\t");
} else {
System.out.print("0\t");
}
if (!p) {
System.out.println("1\t");
} else {
System.out.println("0\t");
}
String oneTab = "1\t";
String zeroTab = "0\t";
p = true;
q = false;
System.out.printf(oneTab + zeroTab);
if (p & q) {
System.out.print(oneTab);
} else {
System.out.print(zeroTab);
}
if (p | q) {
System.out.print(oneTab);
} else {
System.out.print(zeroTab);
}
if (p ^ q) {
System.out.print(oneTab);
} else {
System.out.print(zeroTab);
}
if (!p) {
System.out.println(oneTab);
} else {
System.out.println(zeroTab);
}
p= false ; q = true;
System.out.print(zeroTab + oneTab);
if (p&q) {
when_true();
} else {
when_false();
}
if (p|q) {
when_true();
} else {
when_false();
}
if (p^q) {
when_true();
} else {
when_false();
}
if (!p) {
when_true();
System.out.println();
} else {
when_false();
}
p= false; q= false;
System.out.print(zeroTab + zeroTab);
if (p&q) {
when_true();
} else {
when_false();
}
if (p|q) {
when_true();
} else {
when_false();
}
if (p^q) {
when_true();
} else {
when_false();
}
if (!p) {
when_true();
} else {
when_false();
}
}
static void when_true() {
// System.out.print(oneTab);
System.out.print("1\t");
}
static void when_false() {
System.out.print("0\t");
}
}