# constructor - How to represent a 'long' number as nodes in a linked-list [JAVA]

642 views

### constructor - How to represent a 'long' number as nodes in a linked-list [JAVA]

I have a pragmatic task to solve:

Int and Long numbers that we can store in memory cells are limited in size. One way to solve the problem would be to set up a linked-list in which each node in the list will contain one digit from the number so that the number itself will not be kept as a number but as a collection of its' digits- one after the other.

I have to create a Constructor, which gets a 'long' type of number and stores it in a format of a linked list.

By that I mean that if we take the number 233,674,318 , the Constructor would create a representation of this number as the following : 2 -> 3 -> 3 -> 6 -> 7 -> 4 -> 3 -> 1 -> 8

Could you please suggest me how can I approach this? You can extract a number's least significant digit (the one on the right) using the modulo operator. In this case, `233,674,318 % 10` will yield 8 (`%` signifies modulo). You can get rid of a number's least significant digit using division. `233,674,318 / 10` will yield 23,367,431 which is like removing the 8 from the number. Using these two operations you can extract all the digits from a number and build a list out of them.