i wanted to know if u know how to get the length of digits, like if the user enters 12345 the computer will return 5 because the length is 5

Convert the digit to a String and get the length.

Integer.toString(number).length();

If you want to do it by hand, here is the algorithm I would use:

int numdigits(int num)
{

int len = 0;

while(num >= 10)
{
num = num/10;
len++;
}

return len;
}


Do you need this to work only for positive integers? If yes, then this algorithm will do. If not you could do a few simple manipulations to get it to work for decimals, and negative numbers.

I'm making a linked list of the digits of a number. I found this helpful.thnx

hlut... not only does your answer provide no answer to the question, but this question has been asked (and answered) over 7 years ago.
considering the number of posts of the OP, I'm pretty certain (s)he isn't looking (here) for an answer anymore.

Hi hlut, welcome to DaniWeb.
Thanks for your feedback. It's good to know that people are finding our service useful.

(ps: Don't worry about stultuske's post - I think he misunderstood yours.)

not really.
he creates a linked list, adds each seperate digit to it. I get that. but why having the linked list? by iterating over the digits itself he'd have found the length, no need to actually put them in a linked list.
since the part where the 'counting' could be done in this solution is about the same as what Migsoft suggested, I don't see an added solution, rather a more complicated form of the one already there.
-- but then again, I might be wrong indeed.

I read it as

  • problem statement: "I'm making a linked list of the digits of a number."
  • feedback: " I found this helpful.thnx"

... hence my comments. But only hlut knows for sure...

well ... indeed, I guess it could be read as that ....

I'm new to Daniweb and don't know the rules of the site. Sorry if I stirred trouble.
I'm making a linked list of the digits of a number, then trying to add two numbers in that representaion.

Hey, you are very welcome to the site. You didn't break any rules, you didn't make any trouble. People here tend to post their ideas quite strongly, but we're all good friends, even when we disagree.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.