四则运算

程序设计思想

  使用随机数生成100或1000以内数字,用字符串数组实现+-*/的输出。For循环打印出所需要的题数。

程序流程图

Java四则运算和验证码生成

package yunsuan;
import java.util.Scanner;
public class Yunsuan {

    public static void main(String[] args) {
        int a1,a2,a3;
        int b1,b2,b3;
        int m,n;
        int i=0;
        Scanner sc=new Scanner(System.in);
        String f[]=new String[4];
        f[0]="+";
        f[1]="-";
        f[2]="*";
        f[3]="/";
        System.out.println("请选择100以内或1000以内");
        m=sc.nextInt()+1;
        System.out.println("请输入要产生的题数");
        n=sc.nextInt();
        for(i=0;i<n;i++)
        { 
        a1=(int)(Math.random()*m);
        a2=(int)(Math.random()*m);
        a3=(int)(Math.random()*m);
        //a4=(int)(Math.random()*m);
        b1=(int)(Math.random()*4);
        b2=(int)(Math.random()*4);
        //b3=(int)(Math.random()*4);
        System.out.println("第"+(i+1)+"题:"+a1+f[b1]+a2+f[b2]+a3+"=");
        }
        }
    }
四则运算

相关文章:

  • 2022-12-23
  • 2021-10-24
  • 2021-07-29
  • 2021-07-10
  • 2021-12-31
猜你喜欢
  • 2021-09-07
  • 2022-01-01
  • 2022-01-30
  • 2022-12-23
  • 2021-08-23
  • 2022-12-23
  • 2021-09-27
相关资源
相似解决方案