四则运算
程序设计思想
使用随机数生成100或1000以内数字,用字符串数组实现+-*/的输出。For循环打印出所需要的题数。
程序流程图
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+"="); } } }