cancel
Showing results for 
Search instead for 
Did you mean: 

random nextboolean :(

Former Member
0 Kudos

Hi I have a question regarding this method.. Someone told me that I could generate a random - or + sign with this method but since I'm very new to java programming, I'd like a little help or maybe an example as to how I can achieve it, the example that I'm working on right now is generating two numbers and arithmetic operator (-/+) randomly and then putting them togetherlike say..

1-1 = ?

or 2+2 = ?

I just want to know how can I generate - or + randomly..

I'm going crazzzzzzzyyyyyyyy over this please help guys

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Zumah,

Here you are

int number = new Random().nextInt(2); // this number is '0' or '1'

String minusPlus = (number == 0) ? "-" : "+";

System.out.println(minusPlus);

Regards

Former Member
0 Kudos

edited

Message was edited by:

Zumah gee

Former Member
0 Kudos

Hi Zumah,

Please answer this post as answered since your question was random nextboolean and not this question.

Then you can still ask this new question in a different post.

Later on I can make the program for 10 times then, but please post the EasyIn class as well then.

Answers (1)

Answers (1)

prashil
Advisor
Advisor
0 Kudos

Hi Zumah,

Whatever i understood by your requirement,

i suggest to use random number generator, the number will be in the range of (0.0-0.99)

add a condition like if genrated number is greater than 0.5, then use '+' operator else use '-' operator.

Hope this will help you to find the solution!!!!

Regards,

Prashil