How to use Java to achieve the 10-way addition summation, calculate the correct number of answers, answer the wrong number of ways!

Source: Internet
Author: User

public static void Main (string[] args) {
Scanner input=new Scanner (system.in); Importing import java.util.Random is required;
Random a1=new random (); First pseudo-Random number object
Random a2=new random (); Second pseudo-Random number object
int bool=0;//Defining a computer--the first few questions
int true1=0;//definition How many answers?
int false1=0; The definition answers a few wrong questions
while (BOOL<10) {
System.out.println ("+ (bool+1) +" road title: ");
int One=a1.nextint (100); Receive random numbers, limit random numbers to less than 100
int Two=a2.nextint (100);//Receive random number, limit random number within 100
System.out.print (one+ "+" +two+ "=");
int Sum=input.nextint (); Receive input and/or import java.util.Scanner required; Package
Judge
if (sum== (one+two))
{
SYSTEM.OUT.PRINTLN ("Correct it!" ");
true1++; Calculator, answer right + 1 way
}else{
System.out.println ("wrong answer!") ");
false1++;//Calculator, answer wrong + 1 way
}
bool++;
}
SYSTEM.OUT.PRINTLN ("You answered correctly:" +true1+ "way, Answer wrong:" +false1);
}

How to use Java to achieve the 10-way addition summation, calculate the correct number of answers, answer the wrong number of ways!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.