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.

Results 1 to 4 of 4

Thread: 9^2=81=8+1 How do I do this?

  1. #1
    Junior Member
    Join Date
    Jun 2012
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Exclamation 9^2=81=8+1 How do I do this?

    Take a no, eg 9. Square it.
    92=81

    Now add the digits

    8+1= 9 (Which is the original number)

    How do I do this using Functions?
    It should work for any number. 9, 55, 395 Any.

  2. #2
    Member
    Join Date
    Jan 2012
    Location
    Hellas
    Posts
    284
    Thanks
    11
    Thanked 59 Times in 57 Posts

    Default Re: 9^2=81=8+1 How do I do this?

    Hello siddharthbandhu!
    What have you done so far? Do you have the logic for what you are trying to do?

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: 9^2=81=8+1 How do I do this?

    To get the digits of a number look at using the % and / operators
    If you don't understand my answer, don't ignore it, ask a question.

  4. #4
    Junior Member Tha Boss's Avatar
    Join Date
    Jun 2012
    Location
    ON, Canada.
    Posts
    1
    My Mood
    Cool
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: 9^2=81=8+1 How do I do this?

    you can use .length() to determine how many digits and .charAt() to isolate the numbers and add them using a for loop.