• Post Reply Bookmark Topic Watch Topic
  • New Topic

Storing digits of an integer in an array  RSS feed

 
Abhjit Banerjee
Greenhorn
Posts: 2
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Suppose I have a five digit integer.I wanted to break the integer and store its digits in an array.I am pasting the code upto which I'm done.Please let me know the solution.

 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abhjit Banerjee wrote:Hi,
Suppose I have a five digit integer.I wanted to break the integer and store its digits in an array.I am pasting the code upto which I'm done.Please let me know the solution.




Looks like you done it. The only thing left is to store it into an array, instead of printing it out to standard output.

Henry
 
Abhjit Banerjee
Greenhorn
Posts: 2
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Henry,Thanks for replying so quickly.Actually you got it right,only storing these digits into the array is left.I'm not getting how to do it.

You can see from the code that remainders will be 5,4,3,2,1 respectively.I need to store this into an array to do some manipulation.Can you suggest something.

Abhijit
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What have you tried? Do you know how to declare an array, and how to access individual elements?

We really try to not hand out answers here, but will generally bend over backwards to help you figure it out. Show us what you've tried, tell us what it does, what it doesn't do, what you expect it to do, and how you know what it does.
 
Campbell Ritchie
Marshal
Posts: 56576
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

A little hint which might help about arrays: you can never have an int with more than ten decimal digits in. Beware with % and negative values, however.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!