on 04-16-2007 12:34 AM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
95 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.