+ 1

Попробуйте видоизменить программу таким образом, чтобы вместо логических значений true и false отображались значения 1 и 0.

class LogicalOpTable { public static void main(String[] args) { boolean p,q; System.out.println (" P " + "\t Q " + "\t and " + "\t OR " + "\t XOR " +"\t NOT "); p = true ; q = true; System.out.println (p + " \t " + q + " \t " + (p&q) + " \t " + (p|q) + " \t " + (p^q) + " \t " + (!p)); p = true ; q = false; System.out.println (p + " \t " + q + "\t " + (p&q) + "\t " + (p|q) + " \t " + (p^q) + " \t " + (!p)); p = false; q = true; System.out.println (p + "\t " + q + " \t " + (p&q) + "\t " + (p|q) + " \t " + (p^q) + " \t " + (!p)); p = false; q = false; System.out.println (p + "\t " + q + "\t " + (p&q) + " \t" + (p|q) + "\t " + (p^q) + "\t " + (!p)); } }

29th Jan 2019, 4:27 PM
Иван Иван
Иван Иван - avatar
3 Answers
+ 1
Пример программы реализующей решение. https://code.sololearn.com/c4IeIAzKB9U1
29th Jan 2019, 4:57 PM
Иван Иван
Иван Иван - avatar
+ 1
***ЧАСТЬ_1*** System.out.println ("__P___\t" + "___Q__ \t" + "__&__ \t" + "__|__ \t" + "__^__ \t" +"__!p__"); // p = true q = true p = true ; q = true; if (p&q) { int x =1; System.out.print (p + "__" + "\t_" + q + "_\t __" + x + "__ ");} else { int x = 0; System.out.print ("_" + p +"_" + " \t " + q + " \t __" + x + "__ "); } if (p|q) { int x = 1; System.out.print ("\t __" + x +"__"); } else { int x = 0; System.out.print ("\t__" + x +"___ "); } if (p ^ q) { int x = 1; System.out.print ("\t __" + x +"__"); } else { int x = 0; System.out.print ("\t __" + x +"__"); } if (!p) { int x = 1; System.out.println ("\t__" + x +"__"); } else { int x = 0; System.out.println ("\t __" + x +"___"); } // p = true q = false p = true ; q = false; if (p&q) { int x =1; System.out.print (p + "__ \t_" + q + "_\t __" + x + "__ ");} else { int x = 0; System.out.print (p +"__" + " \t" + q + " \t__" + x + "__ "); } if (p|q) { int x = 1; System.out.print ("\t __" + x +"__"); } else { int x = 0; System.out.print ("\t__" + x +"___ "); } if (p ^ q) { int x = 1; System.out.print ("\t __" + x +"__"); } else { int x = 0; System.out.print ("\t __" + x +"__"); } if (!p) { int x = 1; System.out.println ("\t__" + x +"__"); } else { int x = 0; System.out.println ("\t __" + x +"___"); } // p = false q = true p = false; q = true; if (p&q) { int x =1; System.out.print (p + "_ \t_" + q + "_\t __" + x + "__ ");} else { int x = 0; System.out.print (p +"_" + " \t" + q + "_ \t__" + x + "__ "); }
29th Jan 2019, 4:40 PM
Иван Иван
Иван Иван - avatar
+ 1
***ЧАСТЬ_2*** if (p|q) { int x = 1; System.out.print ("\t __" + x +"__"); } else { int x = 0; System.out.print ("\t__" + x +"___ "); } if (p ^ q) { int x = 1; System.out.print ("\t __" + x +"__ "); } else { int x = 0; System.out.print ("\t __" + x +"__"); } if (!p) { int x = 1; System.out.println ("\t__" + x +"__"); } else { int x = 0; System.out.println ("\t __" + x +"___"); } // p = false q = false p = false; q = false; if (p&q) { int x =1; System.out.print (p + "__ \t_" + q + "\t __" + x + "__ ");} else { int x = 0; System.out.print (p +"_" + " \t" + q + " \t__" + x + "__ "); } if (p|q) { int x = 1; System.out.print ("\t __" + x +"__"); } else { int x = 0; System.out.print (" \t__" + x +"___ "); } if (p ^ q) { int x = 1; System.out.print ("\t __" + x +"__"); } else { int x = 0; System.out.print ("\t__" + x +"__"); } if (!p) { int x = 1; System.out.println (" \t__" + x +"__"); } else { int x = 0; System.out.println ("\t __" + x +"___"); }
29th Jan 2019, 4:54 PM
Иван Иван
Иван Иван - avatar