zoukankan      html  css  js  c++  java
  • 二柱子计算题

    非分数四则运算

    public class compute4 {
    
        /**
         * @param args
         */
        public static void main(String[] args) {
            // TODO Auto-generated method stub
    //四则运算
            for(int i=0;i<30;i++)
            {
            int operate;
            int x,y;
            operate=1+(int)(Math.random()*4);
            x=1+(int)(Math.random()*10);
            y=1+(int)(Math.random()*10);
            if(operate==1)
            {
                System.out.println(x+"*"+y+"="+(x*y));
            }
            if(operate==2)
            {
                if(x%y!=0)
                {
                    if(x%y==x)
                    {
                        System.out.println(x+"/"+y+"="+x+"/"+y);
                    }
                    else
                    {
                        System.out.println(x+"/"+y+"="+(x/y)+"又"+(x%y)+"/"+y);
                    }
                }
                else
                {
                    System.out.println(x+"/"+y+"="+(x/y));    
                }
            }
            if(operate==3)
            {
                System.out.println(x+"+"+y+"="+(x+y));
            }
            if(operate==4)
            {
                System.out.println(x+"-"+y+"="+(x-y));
            }
            }
        }
    
        
    }
    
        

    运行结果截图

    分数四则运算

    public class computef {
    
        /**
         * @param args
         */
        public static void main(String[] args) {
            // TODO Auto-generated method stub
    
            //分数运算
            for(int i=0;i<30;i++)
            {
                    int a,b,c,d;
                    a=1+(int)(Math.random()*10);
                    b=1+(int)(Math.random()*10);
                    c=1+(int)(Math.random()*10);
                    d=1+(int)(Math.random()*10);
                    int operate;
                    operate=1+(int)(Math.random()*4);
                    if(operate==1)
                    {
                        int fz,fm;
                        fm=b*d;
                        fz=a*d+c*b;
                        System.out.println(simplify(a,b)+"+"+simplify(c,d)+"="+simplify(fz,fm));
                    }
                    if(operate==2)
                    {
                        int fz,fm;
                        fm=b*d;
                        fz=a*d-c*b;
                        System.out.println(simplify(a,b)+"-"+simplify(c,d)+"="+simplify(fz,fm));
                    }
                    if(operate==3)
                    {
                        int fz,fm;
                        fm=b*d;
                        fz=a*c;
                        System.out.println(simplify(a,b)+"*"+simplify(c,d)+"="+simplify(fz,fm));
                    }
                    if(operate==4)
                    {
                        int fz,fm;
                        fz=a*d;
                        fm=b*c;
                        System.out.println(simplify(a,b)+" / "+simplify(c,d)+"="+simplify(fz,fm));
                    }
            }
        }
        public static String simplify(int a,int b)
        {
            int max=0;
            for(int i=0;i<100;i++)
            {
                
                int n=i+1;
                if(a%n==0&&b%n==0)
                    max=n;
                
            }
            return (String)(a/max+"/"+b/max);
        }
        
    }

    运行结果截图

  • 相关阅读:
    layui下拉框数据过万渲染渲染问题解决方案
    eclipse debug启动时tomcat报错
    用eclipse的同一个tomcat启动两个javaweb项目
    Json
    @ResponseBody
    SpringMVC Controller 介绍
    tianmao项目的学习笔记
    Thymeleaf入门
    Thymeleaf th:include,th:replace使用
    X 在Windows上使用orakill结束oracle会话的线程
  • 原文地址:https://www.cnblogs.com/clueless/p/6491934.html
Copyright © 2011-2022 走看看