Hello all.
I have a small problem, i need to recieve a 8 digit number for example:
12345678
87654321
and so on.
After i need to devide the value and use the int as a array, something like
int i=123;
System.out.println(i[1]);
It should return 2 (therocially), but obviously the doesnt compile.
I was thinking on making the array of ints, but to read it i will need spaces and that is not acceptable, was already thinking about working with pointers, but found out that java doesnt have pointers.
Any ideias?
jen140 0 Junior Poster
Recommended Answers
Jump to Postint i=123;
System.out.println(i[1]);
Any ideias?'i' is an int, not an array:
int [] i = new int[2]; i[0] = 1; i[1] = 2; i[2] = 3; System.out.println(i[1]);
Jump to PostHere's a possible solution. Not sure what you are trying to accomplish, but this sounds like it should do it. There are probably better options.
int i; String myNumberAsString; myNumberAsString = Integer.toString(i);
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Integer.html#toString(int)
Then you can use the String function "charAt".
Jump to PostJust modulus (%) by ten. That will give you the last digit.
All 10 Replies
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
tux4life 2,072 Postaholic
jen140 0 Junior Poster
cgeier 187 Junior Poster
jen140 commented: Thanks =) +1
BestJewSinceJC 700 Posting Maven
jen140 0 Junior Poster
BestJewSinceJC 700 Posting Maven
jen140 0 Junior Poster
BestJewSinceJC 700 Posting Maven
jen140 0 Junior Poster
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.