[algogeeks] Re: Obtaining each digit from an integer in Java.

2006-09-22 Thread Lego Haryanto
Why do you have to convert n to String again and again in the loop, and doing a substring for only one character?  Can't you just store the string once in the very beginning of your program and just do charAt(i) - '0' in every loop?   No doubt it will work, though.  On 9/22/06, Mukul Gandhi <[EMAI

[algogeeks] Re: Obtaining each digit from an integer in Java.

2006-09-22 Thread Mukul Gandhi
This is a complete Java program doing this: class X { public static void main(String[] args) { int n = 5732; int len = ((new Integer(n)).toString()).length(); int[] array = new int[len]; for (int i = 0; i < len; i++) { String x = ((new Integer(n)).toStr

[algogeeks] Re: Obtaining each digit from an integer in Java.

2006-09-17 Thread Bullislander05
Thank you very much Vishal. I will certainly use this algorithm. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com To unsubscri

[algogeeks] Re: Obtaining each digit from an integer in Java.

2006-09-17 Thread Vishal
N = 5732 (in example)while ( N > 0 ){ push( N % 10 ); N = N / 10;}This will give you digits in reverse order. Read it in reverse order or store it in stack.~Vishal On 9/17/06, Bullislander05 <[EMAIL PROTECTED]> wrote: Hello,I'm fairly new to these parts and I come to ask a question.If anyon