java 出计算题

import java.util.Scanner;


public class suanshu {

 public static void main(String[] args) {
  // TODO Auto-generated method stub
  Scanner input = new Scanner(System.in);
  int m=0;
  while(m==0)
  {
   System.out.println("***************");
   System.out.println("请输入要选择的选项:");
   System.out.println(" 1.整数  ");
   System.out.println(" 2.分数  ");
   System.out.println(" 3.退出  ");
   System.out.println("***************");
   System.out.println(" 请选择:");
   int a = input.nextInt();
   if(a==1)
   {
    System.out.println("输入题目数量");
    shu(input.nextInt());
   }
   if(a==2)
   {
    System.out.println("输入题目数量");
    fen(input.nextInt());
   }
   if(a==3)
   {
    System.out.println("已退出");
    System.exit(0);
   }
  }
 }
 public static void fen(int a) {
  for(int b=0;b<a;b++)
  {
   int x = (int)(Math.random()*100);
   int y = (int)(Math.random()*100);
   int m = (int)(Math.random()*100);
   int n = (int)(Math.random()*100);
   int z = 1+(int)(Math.random()*4);
   if(z==1)
   {
    if(x<y&&m<n)
    {
     System.out.println("("+x+"/"+y+")"+"+"+"("+m+"/"+n+")"+"="+"?");
    }
    else if(x<y&&m>n)
    {
     System.out.println("("+x+"/"+y+")"+"+"+"("+n+"/"+m+")"+"="+"?");
    }
    else if(x>y&&m>n)
    {
     System.out.println("("+y+"/"+x+")"+"+"+"("+n+"/"+m+")"+"="+"?");
    }
    else
    {
     System.out.println("("+y+"/"+x+")"+"+"+"("+m+"/"+n+")"+"="+"?");
    }
   }
   if(z==2)
   {
    if(x<y&&m<n)
    {
     System.out.println("("+x+"/"+y+")"+"-"+"("+m+"/"+n+")"+"="+"?");
    }
    else if(x<y&&m>n)
    {
     System.out.println("("+x+"/"+y+")"+"-"+"("+n+"/"+m+")"+"="+"?");
    }
    else if(x>y&&m>n)
    {
     System.out.println("("+y+"/"+x+")"+"-"+"("+n+"/"+m+")"+"="+"?");
    }
    else
    {
     System.out.println("("+y+"/"+x+")"+"-"+"("+m+"/"+n+")"+"="+"?");
    }
   }
   if(z==3)
   {
    if(x<y&&m<n)
    {
     System.out.println("("+x+"/"+y+")"+"*"+"("+m+"/"+n+")"+"="+"?");
    }
    else if(x<y&&m>n)
    {
     System.out.println("("+x+"/"+y+")"+"*"+"("+n+"/"+m+")"+"="+"?");
    }
    else if(x>y&&m>n)
    {
     System.out.println("("+y+"/"+x+")"+"*"+"("+n+"/"+m+")"+"="+"?");
    }
    else
    {
     System.out.println("("+y+"/"+x+")"+"*"+"("+m+"/"+n+")"+"="+"?");
    }
   }
   if(z==4)
   {
    if(x<y&&m<n)
    {
     System.out.println("("+x+"/"+y+")"+"/"+"("+m+"/"+n+")"+"="+"?");
    }
    else if(x<y&&m>n)
    {
     System.out.println("("+x+"/"+y+")"+"/"+"("+n+"/"+m+")"+"="+"?");
    }
    else if(x>y&&m>n)
    {
     System.out.println("("+y+"/"+x+")"+"/"+"("+n+"/"+m+")"+"="+"?");
    }
    else
    {
     System.out.println("("+y+"/"+x+")"+"/"+"("+m+"/"+n+")"+"="+"?");
    }
   }
  }
  
 }
 public static void shu(int a)
 {
  for(int b=0;b<a;b++)
  {
   int x = (int)(Math.random()*100);
   int y = (int)(Math.random()*100);
   int z = 1+(int)(Math.random()*4);
   if(z==1)
   {
    System.out.println(x+"+"+y+"="+"?");
   }
   if(z==2)
   {
    if(x>y)
    {
     System.out.println(x+"-"+y+"="+"?");
    }
    else
    {
     System.out.println(y+"-"+x+"="+"?");
    }
   }
   if(z==3)
   {
    System.out.println(x+"*"+y+"="+"?");
   }
   if(z==4)
   {
    System.out.println(x+"/"+y+"="+"?");
   }
  }
 }
}

 

转载于:https://www.cnblogs.com/gong123/p/6492062.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值