Software Engineering (second job)

Source: Internet
Author: User
Tags case statement

Requirements Analysis Function Requirements:

1, can automatically generate primary school arithmetic topic.

2, the program can accept the user input answers, and determine the right and wrong.

3, give the total number of correct.


1. Define s as a set of 1 to 4 random numbers, using the which (s) statement, Case S is the subtraction of arithmetic respectively. Define two variables in the case statement, A and B, so that they can produce a random number between 0 and 100 for arithmetic.

2, which statement outer layer in the writing of a while statement, so that which can loop multiple times, multiple calculations.

3, define an H record the correct number of questions, the initial value is 0.

Code implementation


Import Java.util.Scanner;

public class Ruanjian {

public static int Suiji (int num1,int num2) {
int c= (int) num1+ (int) (Math.random () * (NUM2-NUM1));
return C;
public static void Main (string[] args) {

int s,a,b,i=1,f=0,h=0;
Double D;
while (i<=5) {
S=suiji (1,4);
A=suiji (0,100);
B=suiji (0,100);
Switch (S) {
Case 1:
System.out.println (A + "+" +b+ "=");
Scanner reader=new Scanner (;
D=reader.nextint ();
if (d==a+b) {
System.out.println ("The Wrong answer is:" + (a+b));

Case 2:
System.out.println (A + "*" +b+ "=");
Scanner reader1=new Scanner (;
D=reader1.nextint ();
if (d==a*b) {
System.out.println ("The Wrong answer is:" + (a*b));

Case 3:
System.out.println (A + "-" +b+ "=");
Scanner reader2=new Scanner (;
D=reader2.nextint ();
if (d==a-b) {
System.out.println ("The Wrong answer is:" + (A-B));

Case 4:
System.out.println (A + "/" +b+ "=");
Scanner reader3=new Scanner (;
D=reader3.nextint ();
if (d==a/b) {
System.out.println ("Wrong answer:" + (A/b));

SYSTEM.OUT.PRINTLN ("You have correctly answered the" +h+ "question");


Program Effect:

PSP Time-consuming statistics


For the program of writing ideas in advance written on the manuscript, only spent one night to write the simplest code, but in the process of modification encountered several problems, for break and continue choice was once in trouble, because my code when running multiple calculations, A and B display the same value, I thought it was break and continue didn't have a choice, but after consulting the teacher, I found that the steps I defined for a and B to generate random numbers were written before the while loop. In addition, I hope to be able to list several topics at the same time after the design improvement, so that the user can write the answer at the same time.

Software Engineering (second job)

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: 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.