Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 2 of 2 FirstFirst 12
Results 26 to 31 of 31

Thread: Need some math help

  1. #26
    Member
    Join Date
    Aug 2014
    Posts
    38
    My Mood
    Confused
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Need some math help

    Quote Originally Posted by Norm View Post
    In your example what would be the values in the array at the end of each of the steps?
    X=1234

    Y[4] (creates an array of way with 4 shelves/things to store numbers in)

    Y[0] = 1
    Y[1] = 2
    Y[2] = 3
    Y[3] = 4

    Next I add 7 to the numbers

    Y[0] = 1+7 This would be 8
    Y[1] = 2+7 This would be 9
    Y[2] = 3+7 This would be 10
    Y[3] = 4+7 This would be 11

    Then I do that get the remainder after dividing by 10 thing

    Y[0] = Y[0] % 10 This becomes 8
    Y[1] = Y[1] % 10 This becomes 9
    Y[2] = Y[2] % 10 This becomes 1
    Y[3] = Y[3] % 10 This becomes 2

    Not sure if these outcomes are 100% correct. I'm trying to do a couple different home works at once.

    Quote Originally Posted by Norm View Post
    What math steps would need to be done to "undo" the % operator? Make a list of numbers that are possible values in this program (7-16), apply % to them and then look at what would need to be done to get back the original numbers.
    For example:
    7 % 10 = 7 Nothing needed to restore 7
    16 % 10 = 6 add 10 to get 16
    So...if a number is between 8 and 9 then just subtract 7 from it? if its anything else add 10 to it, then subtract 7?
    Last edited by mattig89ch; September 26th, 2014 at 11:58 AM. Reason: Math mistakes

  2. #27
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,145
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Need some math help

    There are only 10 different numbers so you should be able to see how to convert each one of them to the original value.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #28
    Member
    Join Date
    Aug 2014
    Posts
    38
    My Mood
    Confused
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Need some math help

    wooo! it works! Thanks for the help all!

    Two last questions.

    First, is it possible to combine the 4 elements in the array into a single int?

    Second, is it possible to have java read the length of the initial int? so I can tell a user they didn't enter a long enough number, or too long of a number.

  4. #29
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,145
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Need some math help

    is it possible to combine the 4 elements in the array into a single int?
    Yes. You need to define the value in each slot's relationship to the other slots in the array.

    Remember how our number system works:
    1234 is the sum of these 4 values:
    1*1000
    2*100
    3*10
    4*1
    The factors are 10 to a power.

    have java read the length of the initial int
    I assume you mean how many digits a number displayed in base 10 takes. int values are stored in binary format in a 32 bit area of memory.

    One way to see the number of digits would be by testing the value against the smallest and highest value with the desired number of digits. For 2 digits: 10 to 99
    Also since most user input is read as a String, use a String class method to determine the length of the String.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #30
    Member
    Join Date
    Aug 2014
    Posts
    38
    My Mood
    Confused
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Need some math help

    wew! Thanks for the help again all. Grade 100! Thanks to your help.

    Forum Question now, I have another math question(s) for my next hw assignment. Would it be better to just start a new topic, or to keep going with this old one?

  6. #31
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,145
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Need some math help

    Start a new thread for a new problem.
    If you don't understand my answer, don't ignore it, ask a question.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Question about math.pow and math.sqrt
    By ggx7 in forum Java Theory & Questions
    Replies: 7
    Last Post: March 7th, 2014, 12:51 PM
  2. Math.E - what exactly is it?
    By RedCloudTsunami in forum Java Theory & Questions
    Replies: 2
    Last Post: July 10th, 2012, 12:24 AM
  3. [SOLVED] Help with Math.tan and Math.atan
    By Dr.Code in forum Algorithms & Recursion
    Replies: 6
    Last Post: July 2nd, 2012, 05:54 AM
  4. Confusion with Math.toDegrees() and Math.toRadians(). Please help.
    By marksquall in forum Java Theory & Questions
    Replies: 3
    Last Post: June 23rd, 2011, 01:28 AM
  5. Math Drill
    By Java Neil in forum What's Wrong With My Code?
    Replies: 11
    Last Post: February 5th, 2011, 01:12 AM