Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-31-2007, 07:11 AM
Member
 
Join Date: Jul 2007
Posts: 40
cachi is on a distinguished road
Generates random maths questions
Hi, I am writing a program that generates random maths questions for primary schools, but I'm having a problem finding out how to select one of the following characters at random (+ - * /).
Please can you help?

Thanks.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-31-2007, 09:51 AM
Member
 
Join Date: Jul 2007
Posts: 10
nitinborge5 is on a distinguished road
hi cachi
do one thing convert characters in string[]

and from that u can get your charactor randomly

with help of equals method u can get apropriate operator

ok
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-31-2007, 04:09 PM
Senior Member
 
Join Date: Jul 2007
Posts: 134
brianhks will become famous soon enough
Do what was previously stated and use Random.nextInt(4). It will return you either 0,1,2 or 3. You can use that to get one of the symbols from the array.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 08-01-2007, 06:39 AM
Member
 
Join Date: Aug 2007
Posts: 15
yiweiang is on a distinguished road
yes, so to further explain that, it means that
if (x=0)
{
selectedSymbol=plus;
}

...etc
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 08-01-2007, 06:48 AM
Senior Member
 
Join Date: Jul 2007
Posts: 134
brianhks will become famous soon enough
Don't use an if statement at all.
Code:
String[] operators = {"+", "-", "*", "/"}; Random rand = new Random(); String op = operators[rand.nextInt(4)];
Just loop that last line as you create your math problems.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
random numbers without random class` carlos123 New To Java 4 01-18-2008 12:44 AM
Just a Few Questions pringle New To Java 21 01-09-2008 08:21 PM
Maths table.. what am I doing wrong (probably everything!! :p ) ad0m New To Java 15 11-30-2007 07:19 PM
questions Gilgamesh New To Java 3 11-28-2007 01:18 AM
3 Questions hiranya AWT / Swing 4 11-14-2007 06:57 AM


All times are GMT +3. The time now is 09:20 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org