• Java四则运算


     1 package androidtextfirst;
     2 
     3 import java.util.Random;
     4 
     5 import javax.swing.JOptionPane;
     6 
     7 public class schooltext2 {
     8 
     9 public static void main(String[] args) {
    10 int m = 1;
    11 int a = 0, b = 0, c = 0, d = 0, e = 0;
    12 int x = 0;
    13 String p = "", q = "";
    14 Random random = new Random();
    15 
    16 for (int w = 0; w < 1000000000; w++) {
    17 String input = JOptionPane.showInputDialog("请输入选择:1、整数 2、真分数 3、退出程序");
    18 x = Integer.parseInt(input);
    19 if (x == 1) {
    20 for (int i = 0; i < 300; i++) {
    21 a = random.nextInt(99);
    22 b = random.nextInt(99);
    23 c = random.nextInt(3);
    24 if (c == 0) {
    25 System.out.println(a + "+" + b + "=");
    26 }
    27 if (c == 1) {
    28 System.out.println(a + "-" + b + "=");
    29 }
    30 if (c == 2) {
    31 System.out.println(a + "*" + b + "=");
    32 }
    33 if (c == 3) {
    34 if (b != 0) {
    35 System.out.println(a + "/" + b + "=");
    36 }
    37 if (b == 0) {
    38 i--;
    39 }
    40 }
    41 
    42 }
    43 }
    44 if (x == 2) {
    45 for (int r = 0; r < 300; r++) {
    46 a = random.nextInt(99);
    47 b = random.nextInt(99);
    48 d = random.nextInt(99);
    49 e = random.nextInt(99);
    50 c = random.nextInt(3);
    51 if ((a >= b && b != 0) || a == 0) {
    52 p = a + "/" + b;
    53 } else {
    54 p = b + "/" + a;
    55 }
    56 if ((d >= e && e != 0) || d == 0) {
    57 q = d + "/" + e;
    58 } else {
    59 q = e + "/" + d;
    60 }
    61 if (c == 0) {
    62 System.out.println(p + "+" + q);
    63 }
    64 if (c == 1) {
    65 System.out.println(p + "-" + q);
    66 }
    67 if (c == 2) {
    68 System.out.println(p + "*" + q);
    69 }
    70 if (c == 3) {
    71 if (d == 0 || e == 0) {
    72 r--;
    73 } else {
    74 System.out.println(p + "/" + q);
    75 }
    76 }
    77 }
    78 }
    79 if (x == 3) {
    80 break;
    81 }
    82 }
    83 }
    84 }

  • 相关阅读:
    python os.path
    ant的基本说明
    gcc的基本使用方法
    java逻辑运算符小节
    awk 简单教程
    推荐:恢复Ext3下被删除的文件
    python读取excel
    ant的简明教程,后面运行写的不错
    WinForm中快捷键与组合按键的设置
    InstallShield 2010集成.net Framework 4的安装包制作
  • 原文地址:https://www.cnblogs.com/ly97/p/6515762.html
Copyright © 2020-2023  润新知