Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Mar 2005
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Problem with Java

    Hi,

    I am writing a rogram that generates random maths questions for primary schools, but im having a problem finding out how to select one of the following characters at random (+ - * /). PLease can you help?

    Kuskyboy

  • #2
    Regular Coder
    Join Date
    Dec 2003
    Posts
    367
    Thanks
    0
    Thanked 0 Times in 0 Posts
    There are many ways to solve that. Here is one:
    Code:
    switch (someRandomIntegerBetweenZeroAndThree) {
      case 0:
        operator = '+';
        break;
      case 1:
        operator = '-';
        break;
      case 2:
        operator = '*';
        break;
      case 3:
        operator = '/';
        break;
    }
    shmoove

  • #3
    New Coder
    Join Date
    Mar 2005
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks very much for that.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •