# How to parse an multidigit in an sequence of particular digits

• October 26th, 2013, 05:33 PM
stut
How to parse an multidigit in an sequence of particular digits
For example we have a number 1709. How to define every digit of the number. Should we cast type to string. Then to parse it with toCharArray method. And use the indexes to have an access to char array of this particular digit also with reversal type casting. For example: int number=1709; char [] array=number.toCharArray(); int b=9; int suma=b+(int)array[0]; System.out.print(suma); is it correct at least in principle or we should use other way?
• October 26th, 2013, 06:07 PM
Norm
Re: How to parse an multidigit in an sequence of particular digits
Quote:

is it correct
What have you tried? What happened? The compiler will tell you if the syntax is correct.

If you have questions about java code, post the code and be sure to wrap the code in code tags.

See the Integer class has a method for creating a String from an int value.
• October 27th, 2013, 12:42 AM
rodiongork
Re: How to parse an multidigit in an sequence of particular digits
You'd better explain why you need it.

If this is a kind of school task, then you are really supposed to divide number by 10 several times keeping remainders.

Here is a short explanation:
Wiki: Number to Digits - CodeAbbey

Though for industrial usage of course you can convert number to string and get bytes of it. Especially if you are not interested in numeric values of digits themselves.
• November 1st, 2013, 01:24 AM
stut
Re: How to parse an multidigit in an sequence of particular digits
No I need numeric values of this digits. So I do not understand why to convert int number to String and than get bytes of it. As I know: when I use string[0] it doesnt mean that is the first letter (digit)-but the first string in array of string. Or am I not correct? I need access to the symbols of numbers so as I understand that I need a char array: char [] num={1,7,0,9}. Than I need to know if the first digit is dividable to 2, or all digits. Maybe be authors of such test tasks precepitated the using of "divide by 10" but if we would need to know the divideness of the second or third digit it should be more difficutlu to use this method. /So this I need for the test in software firm that engaged in industrial programming. So I would be gratefull for the help. What method Of String class I need, is it possible to use toCharArray method or just divide by 10?
• November 1st, 2013, 07:50 AM
Norm
Re: How to parse an multidigit in an sequence of particular digits
What have you tried? Post the code you are having problems with.