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

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

1. ## 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. ## 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. ## Re: 9^2=81=8+1 How do I do this?

To get the digits of a number look at using the % and / operators

4. ## 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.