on ‎2007 Apr 16 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
Request clarification before answering.
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.
| User | Count |
|---|---|
| 9 | |
| 5 | |
| 4 | |
| 4 | |
| 3 | |
| 3 | |
| 2 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.