HomeWork05.java 812 B

123456789101112131415161718192021222324252627282930
  1. /**
  2. * @author WanJl
  3. * @version 1.0
  4. * @title HomeWork05
  5. * @description 7月14日课后作业-简易计算器
  6. * @create 2026/7/15
  7. */
  8. public class HomeWork05 {
  9. public static void main(String[] args) {
  10. int a=15,b=20;
  11. char operator='/';
  12. if (operator=='+'){
  13. System.out.println(a+b);
  14. }else if (operator=='-'){
  15. System.out.println(a-b);
  16. }else if (operator=='*'){
  17. System.out.println(a*b);
  18. }else if (operator=='/'){
  19. if (b==0){
  20. System.out.println("除数不能为0");
  21. }
  22. System.out.println(a/b);
  23. }else if (operator=='%'){
  24. if (b==0){
  25. System.out.println("除数不能为0");
  26. }
  27. System.out.println(a%b);
  28. }
  29. }
  30. }