编程语言
首页 > 编程语言> > java——随机口算题(加减乘除随机)

java——随机口算题(加减乘除随机)

作者:互联网

java——随机口算题(加减乘除随机)


import java.util.Scanner;
public class  jisuan
{
 static int wrongnumber=0;
 public static void main(String[] args)
{ 
  for(int i=0;i<5;i++)
  {
   System.out.print((i+1)+"."+ "");
   int a=(int)(System.currentTimeMillis()%4);
   switch(a){
   case 0:add(a);break;
   case 1:jian(a);break;
   case 2:cheng(a);break;
   case 3:chu(a);break;
   }
  }
  System.out.println("wrongnumber is "+wrongnumber);
 }
 public static void add(int a)
 {
   int number1=(int)( System.currentTimeMillis()*3%1000);
   int number2=(int)( System.currentTimeMillis()*7%1000);
   int answer;
   Scanner input=new Scanner(System.in);
   System.out.print(number1+"+"+number2+" = ");
   do
   {
    answer=input.nextInt(); 
    if(number1+number2==answer)
     System.out.println((char)8730);
    if(!(number1+number2==answer))
    {
     wrongnumber++;
     System.out.println(number1+"+"+number2+"="+answer+" is "+(number1+number2==answer));
     System.out.print("please input your answer again : ");
    }
   }while(!(number1+number2==answer));
 }
 public static void jian(int a) 
 {
    int answer;
    int number1=(int)( System.currentTimeMillis()*3%1000);
    int number2=(int)( System.currentTimeMillis()*7%1000);
    if(number1<number2)
    {
     number1=number1^number2;
     number2=number1^number2;
     number1=number1^number2;
    }
    Scanner input=new Scanner(System.in);
    System.out.print(number1+"-"+number2+" = ");
    do {
     answer=input.nextInt();
     if(number1-number2==answer)
      System.out.println((char)8730);
     if(!(number1-number2==answer))
     {
      wrongnumber++;
      System.out.println(number1+"-"+number2+"="+answer+" is "+(number1-number2==answer));
      System.out.print("please input your answer again : ");
     } 
    }while(!(number1-number2==answer));
 }
 public static void cheng(int a) 
 {
   int answer;
   int number1=(int)( System.currentTimeMillis()%100);
   int number2=(int)( System.currentTimeMillis()*7%100);
   Scanner input=new Scanner(System.in);
   System.out.print(number1+"*"+number2+" = ");
   do{
    answer=input.nextInt();
    if(number1*number2==answer)
     System.out.println((char)8730);
    if(!(number1*number2==answer))
    {
     wrongnumber++;
     System.out.println(number1+"*"+number2+"="+answer+" is "+(number1*number2==answer));
     System.out.print("please input your answer again : ");
    }
   }while(!(number1*number2==answer));
 }
 public static void chu(int a)
 {
   int shang,yushu;
   int number1=(int)( System.currentTimeMillis()%1000);
   int number2=(int)( System.currentTimeMillis()*7%100);
   if(number1<number2)
   {
    number1=number1^number2;
    number2=number1^number2;
    number1=number1^number2;
   }
   Scanner input=new Scanner(System.in);
   System.out.print(+number1+"/"+number2+" = ");
   do {
   shang=input.nextInt();
   yushu=input.nextInt();
   if(!(number1/number2==shang&&number1%number2==yushu))
    {
     wrongnumber++;
     System.out.println(number1+"/"+number2+"="+shang+"……" +yushu+" is "+(number1/number2==shang&&number1%number2==yushu));
     System.out.print("please input your answer again : ");
    }
   else
     System.out.println((char)8730);
   }while(!(number1/number2==shang&&number1%number2==yushu));
 }
}
笑不止是表情 发布了11 篇原创文章 · 获赞 0 · 访问量 198 私信 关注

标签:java,int,static,随机,public,算题
来源: https://blog.csdn.net/yulingzheng/article/details/104119185