简体   繁体   English

随机生成一个简单的数学方程,Android Studio

[英]Randomly generating a simple math equation, Android Studio

I'm using android studio to create an app that generates a random equation and the user will input an answer to the randomly generated equation and solve simple 2 digit addition and subtraction, and 1 digit division and multiplication.我正在使用 android studio 创建一个生成随机方程的应用程序,用户将输入随机生成方程的答案并解决简单的 2 位加减法和 1 位除法和乘法。 My problem is I'm unsure what i need to use to generate the random numbers for even a simple add and subtract method.我的问题是我不确定我需要使用什么来为简单的加减法生成随机数。 Do i use something similar to我是否使用类似的东西

Random rand1 = new Random();
int operation1 = rand1.nextInt(100);
Random rand2 = new Random();
int operation2 = rand2.nextInt(100);
int sum = operation1 + operation2;

I feel as though I'm making it more complicated than it needs to be .我觉得好像我让它变得比它需要的更复杂。 Any help would be appreciated.任何帮助,将不胜感激。

One instance of Random should be good for multiple callings of randomization. Random 的一个实例应该适合多次调用随机化。 Depending on what you will need down the line regarding specific output and such will require you to utilize different Random method implementations.根据您对特定输出的需求,这将要求您使用不同的 Random 方法实现。 You're not over-complicating anything aside from that.除此之外,您并没有使任何事情变得过于复杂。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM