当前位置:   article > 正文

德·摩根定律的验证(De Morgan’s Laws)_用逻辑变换器验证徳摩根定理实验步骤

用逻辑变换器验证徳摩根定理实验步骤

有点怀念高一时的代数课程了,第一章集合还是挺友好的,后面的章节就越来越难了哭

代码如下:

  1. //JHTP Exercise 5.23: De Morgan’s Laws
  2. //by pandenghuang@163.com
  3. /*(De Morgan’s Laws) In this chapter, we discussed the logical operators &&, &, ||, |, ^ and !.
  4. De Morgan’s laws can sometimes make it more convenient for us to express a logical expression.
  5. These laws state that the expression !(condition1 && condition2) is logically equivalent to the expression
  6. (!condition1 || !condition2). Also, the expression !(condition1 || condition2) is logically
  7. equivalent to the expression (!condition1 && !condition2). Use De Morgan’s laws to write equivalent
  8. expressions for each of the following, then write an application to show that both the original expression
  9. and the new expression in each case produce the same value:
  10. a) !(x < 5) && !(y >= 7)
  11. b) !(a == b) || !(g != 5)
  12. c) !((x <= 8) && (y > 4))
  13. d) !((i > 4) || (j <= 6))*/
  14. import java.util.Scanner;
  15. public class DeMorganLaw
  16. {
  17. public static void main(String[] args)
  18. {
  19. Scanner input=new Scanner(System.in);
  20. boolean ea,eaDM,eb,ebDM,ec,ecDM,ed,edDM;
  21. int a,b,g,i,j,x,y;
  22. a=b=g=i=j=x=y=0;
  23. ea=!(x < 5) && !(y >= 7);
  24. eaDM=!((x < 5) || !(y >= 7));
  25. eb=!(a == b) || !(g != 5);
  26. ebDM=!((a == b) && !(g != 5));
  27. ec=!((x <= 8) && (y > 4));
  28. ecDM=!(x <= 8) || !(y > 4);
  29. ed=!((i > 4) || (j <= 6));
  30. edDM=!(i > 4) && !(j <= 6);
  31. System.out.printf("请依次输入整数a,b,g,i,j,x,y的值:\n");
  32. a=input.nextInt();
  33. System.out.printf("a=%d\n",a);
  34. b=input.nextInt();
  35. System.out.printf("b=%d\n",b);
  36. g=input.nextInt();
  37. System.out.printf("g=%d\n",g);
  38. i=input.nextInt();
  39. System.out.printf("i=%d\n",i);
  40. j=input.nextInt();
  41. System.out.printf("j=%d\n",j);
  42. x=input.nextInt();
  43. System.out.printf("x=%d\n",x);
  44. y=input.nextInt();
  45. System.out.printf("y=%d\n",y);
  46. System.out.printf("\n以上数值的逻辑运算结果:\n");
  47. System.out.printf("!(x < 5) && !(y >= 7)=%b\n",!(x < 5) && !(y >= 7));
  48. System.out.printf("!((x < 5) ||(y >= 7))=%b\n\n",!((x < 5) || (y >= 7)));
  49. System.out.printf("!(a == b) || !(g != 5)=%b\n",!(a == b) || !(g != 5));
  50. System.out.printf("!((a == b) && !(g != 5))=%b\n\n",!((a == b) && !(g != 5)
  51. ));
  52. System.out.printf("!((x <= 8) && (y > 4))=%b\n",!((x <= 8) && (y > 4)));
  53. System.out.printf("!(x <= 8) || !(y > 4)=%b\n\n",!(x <= 8) || !(y > 4));
  54. System.out.printf("!((i > 4) || (j <= 6))=%b\n",!((i > 4) || (j <= 6)));
  55. System.out.printf("!(i > 4) && !(j <= 6)=%b\n",!(i > 4) && !(j <= 6));
  56. }
  57. }

运算结果:

请依次输入整数a,b,g,i,j,x,y的值:
10
a=10
20
b=20
30
g=30
40
i=40
50
j=50
60
x=60
70
y=70

以上数值的逻辑运算结果:
!(x < 5) && !(y >= 7)=false
!((x < 5) ||(y >= 7))=false

!(a == b) || !(g != 5)=true
!((a == b) && !(g != 5))=true

!((x <= 8) && (y > 4))=true
!(x <= 8) || !(y > 4)=true

!((i > 4) || (j <= 6))=false
!(i > 4) && !(j <= 6)=false

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/522499
推荐阅读
相关标签
  

闽ICP备14008679号