Code implementation for arithmetic of randomly generated fractions or integers

Source: Internet
Author: User

A design idea:

First, complete how to achieve a random two numbers and a arithmetic symbol

Second, how to realize the output in the form of arithmetic problem

Iii. How to achieve the selective output how many questions

Four, how to add the function of the output score

Second, the Code implementation

Package com.minirisoft;

Import java.util.*;

public class Yunsuan {

public static void Main (string[] args) {

Scanner input=new Scanner (system.in);

System.out.println ("Please enter the question of whether you want to output a fractional question or an integer arithmetic title: 0: Score, 1: integer");

int A=input.nextint ();

Switch (a) {

Case 0:

{

SYSTEM.OUT.PRINTLN ("You have selected a score please enter how many arithmetic questions to output");

int J=input.nextint ();

Random t=new random ();

Char arr[] = {' + ', '-', ' * ', '/'};

for (int i=0;i<j;i++) {

System.out.print (T.nextint (+) + "/" + (T.nextint (30) +1) + "");

System.out.print (Arr[t.nextint (4)]);

System.out.println ("+t.nextint (+) +"/"+ (T.nextint (30) +1) +" = ");

}

Break

}

Case 1:

{

SYSTEM.OUT.PRINTLN ("You have selected an integer, please enter how many arithmetic questions to output");

int J=input.nextint ();

Random t=new random ();

Char arr[] = {' + ', '-', ' * ', '/'};

for (int i=0;i<j;i++) {

System.out.print (T.nextint (30));

System.out.print (Arr[t.nextint (4)]);

System.out.println (T.nextint (30) +1+ "=");

}

Break

}

Default:System.out.println ("The number entered is incorrect, please enter 0 or 1");

}

}

}

Third, the experimental results

Four reasons why you can't make a class

First, because forget how to use the random number so that all the attention in this, can not consider the whole problem.

Summary is not often due to their own programming, because of their laziness, the knowledge of the lack of learning forgotten, and later should practice more programming.

Second, a bit sloppy, do not look at the topic, directly to the problem to realize arithmetic to seek results

In short, the current poor programming ability, the future must be more practice.

Code implementation for arithmetic of randomly generated fractions or integers

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.