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));
 }
}

你可能感兴趣的:(JAVA)