Results 1 to 2 of 2
  1. #1
    fernando is offline Member
    Join Date
    Jul 2007
    Posts
    40
    Rep Power
    0

    Default Help with math in java

    Hi, I have written a simple calc that displays times tables or it generates random problems of different operators (i.e., + - x /).
    The problem is the random numbers that are generated do not always result in an integer answer, so u get problems like 10 / 7 = 1. If i use doubles the answer is 1.42857, but this is for a forth class student so i only want problems that will result in an integer answer that is correct not like 10 / 7 = 1.

    Apart from this my first console attempt works fine just need to adapt to applet.
    Thanks.

  2. #2
    brianhks is offline Senior Member
    Join Date
    Jul 2007
    Posts
    135
    Rep Power
    0

    Default

    Use the mod operator to see if the division will result in a whole number. For example in the above problem 10 / 7, you would do 10 % 7 = 3 (% = modulus, it basically returns the remainder). When the modulus equals 0 the answer will be a whole number.

Similar Threads

  1. Math Class
    By ritwik07 in forum New To Java
    Replies: 2
    Last Post: 09-14-2009, 05:06 PM
  2. Java Math
    By levent in forum Java Tutorial
    Replies: 1
    Last Post: 05-12-2008, 10:03 AM
  3. java.lang.Math
    By eva in forum New To Java
    Replies: 2
    Last Post: 01-31-2008, 05:17 PM
  4. Math.Random
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-23-2007, 03:09 PM
  5. Date math
    By orchid in forum New To Java
    Replies: 2
    Last Post: 04-18-2007, 08:01 AM

Posting Permissions

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