Package Csniu;
Import Java.util.Random;
Import Java.util.Scanner;
public class Calculate
{
randomrandom= new Random ();
scannerscanner= new Scanner (system.in);
Intx, Y, answer, right, fault;
public static void Main (string[] args)
{
Calculate Calculate = new Calculate ();
Scanner Scanner = new Scanner (system.in);
System.out.print ("Please select operator. 1 Plus, 2 minus, 3 times, 4 apart. ");
int select = Scanner.nextint ();
System.out.print ("Please specify the number of items.") ");
int time = Scanner.nextint ();
Switch (SELECT)
{
Case 1:
for (int i = 0; i < time; i++)
{
Calculate.add ();
}
System.out.print ("You are against" + calculate.right + "dao, wrong" + Calculate.fault + "Tao. ");
Break
Case 2:
for (int i = 0; i < time; i++)
{
Calculate.sub ();
}
System.out.print ("You are against" + calculate.right + "dao, wrong" + Calculate.fault + "Tao. ");
Break
Case 3:
for (int i = 0; i < time; i++)
{
Calculate.mul ();
}
System.out.print ("You are against" + calculate.right + "dao, wrong" + Calculate.fault + "Tao. ");
Break
Case 4:
for (int i = 0; i < time; i++)
{
Calculate.div ();
}
System.out.print ("You are against" + calculate.right + "dao, wrong" + Calculate.fault + "Tao. ");
Break
Default
Break
}
}
void Randnumber ()
{
x = Random.nextint (11);
y = random.nextint (11);
}
void Add ()
{
Randnumber ();
System.out.println ("Please enter" + x + "+" + y + "The correct answer:");
while (true)
{
Try
{
Scanner Scanner = new Scanner (system.in);
Answer = Scanner.nextint ();
Break
}
catch (Exception e)
{
System.out.println ("Please enter an integer. ");
}
}
if (Answer! = (x + y))
{
fault++;
}
Else
{
right++;
}
}
void Sub ()
{
Randnumber ();
if (x < y)
{
System.out.print ("Please enter" + y + "-" + x + "The correct answer:");
Answer = Scanner.nextint ();
if (answer! = (y-x))
{
fault++;
}
Else
{
right++;
}
}
System.out.println ("Please enter" + x + "-" + y + "The correct answer:");
while (true)
{
Try
{
Scanner Scanner = new Scanner (system.in);
Answer = Scanner.nextint ();
Break
}
catch (Exception e)
{
System.out.println ("Please enter an integer. ");
}
}
if (Answer! = (x-y))
{
fault++;
}
Else
{
right++;
}
}
void Mul ()
{
Randnumber ();
System.out.println ("Please enter" + x + "*" + y + "The correct answer:");
while (true)
{
Try
{
Scanner Scanner = new Scanner (system.in);
Answer = Scanner.nextint ();
Break
}
catch (Exception e)
{
System.out.println ("Please enter an integer. ");
}
}
if (Answer! = (x * y))
{
fault++;
}
Else
{
right++;
}
}
void Div ()
{
Randnumber ();
if (x==0)
{
System.out.print ("Please enter" + y + "/" + x + "for the correct answer:");
Answer = Scanner.nextint ();
if (answer! = (y/x))
{
fault++;
}
Else
{
right++;
}
}
System.out.println ("Please enter" + x + "/" + y + "for the correct answer:");
while (true)
{
Try
{
Scanner Scanner = new Scanner (system.in);
Answer = Scanner.nextint ();
Break
}
catch (Exception e)
{
System.out.println ("Please enter an integer. ");
}
}
if (Answer! = (x/y))
{
fault++;
}
Else
{
right++;
}
}
}1: Judging user input
14:16:43
2:
14:16:59
Subtraction does not allow negative results
14:17:15
3: Division does not allow the divisor to be 0 My pair programming object is Wang He summary: Through this work, so that we understand each other's ideas deepen our friendship can also help each other, teach each other, can get the ability to complement each other. In programming, talking to each other can solve problems faster and more efficiently.
Third time job