四则运算01
发布日期:2021-10-24 12:41:31 浏览次数:2 分类:技术文章

本文共 989 字,大约阅读时间需要 3 分钟。

编写随机生成30道小学数学题目:

源代码:

package test;public class  lianxi {    String f()    {        int i = (int)(Math.random()*10);        int j = (int)(Math.random()*10);        if(i>j)        {            int temp = i;            i = j;            j = temp;        }        return ("("+i+"/"+j+")");    }public static void main(String[] args){    String a,b;    int k;    lianxi lianxi = new lianxi();    for(int n=0;n<30;n++){        a=lianxi.f();        b=lianxi.f();        int i=(int)(Math.random()*100);        int j=(int)(Math.random()*100);        switch((int)(Math.random()*4)){        case 0:            k = (int)(Math.random()*3);            if(k==0)                System.out.println(i+"+"+j+"=");            else if(k==1)                System.out.println(a+"+"+j+"=");            else if(k==2)                System.out.println(b+"+"+a+"=");            break;        case 1:            k = (int)(Math.random()*3);            if(i

结果截图:

转载于:https://www.cnblogs.com/huyangyang/p/6491309.html

转载地址:https://blog.csdn.net/weixin_30784141/article/details/98368137 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:如何进入docker容器
下一篇:【大数据】分布式集群部署

发表评论

最新留言

第一次来,支持一个
[***.219.124.196]2024年04月15日 22时37分02秒