Hi All,
Here is an example of how you can do logical operations
in Java.
What do you think it will print?
Try it!
Regards,
- DL
public class LogicalOperators {
boolean tt [][] = {
{false, false},
{false, true},
{true, false},
{true, true}
};
public static void main(String args[]) {
LogicalOperators lo
= new LogicalOperators();
lo.println();
}
public void println() {
System.out.println("TruthTable");
System.out.println("a\tb\ta&&b\ta||b\t!a");
for (int x=0; x < tt.length; x++) {
boolean a = tt[x][0];
boolean b = tt[x][1];
System.out.println(a+"\t"+b+"\t"
+(a&&b)+"\t"
+(a||b)+"\t"
+(!a));
}
}
}
|