Hi everybody.

I'm working on my program. And have this output storred in the object puzzle:

Puzzle is:
   1   5   9  13   2   6  10  14   3   7  11  15   4   8  12  16
   2   6  10  14   3   7  11  15   4   8  12  16   5   9  13   1
   3   7  11  15   4   8  12  16   5   9  13   1   6  10  14   2
   4   8  12  16   5   9  13   1   6  10  14   2   7  11  15   3
   5   9  13   1   6  10  14   2   7  11  15   3   8  12  16   4
   6  10  14   2   7  11  15   3   8  12  16   4   9  13   1   5
   7  11  15   3   8  12  16   4   9  13   1   5  10  14   2   6
   8  12  16   4   9  13   1   5  10  14   2   6  11  15   3   7
   9  13   1   5  10  14   2   6  11  15   3   7  12  16   4   8
  10  14   2   6  11  15   3   7  12  16   4   8  13   1   5   9
  11  15   3   7  12  16   4   8  13   1   5   9  14   2   6  10
  12  16   4   8  13   1   5   9  14   2   6  10  15   3   7  11
  13   1   5   9  14   2   6  10  15   3   7  11  16   4   8  12
  14   2   6  10  15   3   7  11  16   4   8  12   1   5   9  13
  15   3   7  11  16   4   8  12   1   5   9  13   2   6  10  14
  16   4   8  12   1   5   9  13   2   6  10  14   3   7  11  14

What I would like to knowis how to get every single number and store them in the array, or even better in 2D array.

Hi everybody.

I'm working on my program. And have this output storred in the object puzzle:

Puzzle is:
   1   5   9  13   2   6  10  14   3   7  11  15   4   8  12  16
   2   6  10  14   3   7  11  15   4   8  12  16   5   9  13   1
   3   7  11  15   4   8  12  16   5   9  13   1   6  10  14   2
   4   8  12  16   5   9  13   1   6  10  14   2   7  11  15   3
   5   9  13   1   6  10  14   2   7  11  15   3   8  12  16   4
   6  10  14   2   7  11  15   3   8  12  16   4   9  13   1   5
   7  11  15   3   8  12  16   4   9  13   1   5  10  14   2   6
   8  12  16   4   9  13   1   5  10  14   2   6  11  15   3   7
   9  13   1   5  10  14   2   6  11  15   3   7  12  16   4   8
  10  14   2   6  11  15   3   7  12  16   4   8  13   1   5   9
  11  15   3   7  12  16   4   8  13   1   5   9  14   2   6  10
  12  16   4   8  13   1   5   9  14   2   6  10  15   3   7  11
  13   1   5   9  14   2   6  10  15   3   7  11  16   4   8  12
  14   2   6  10  15   3   7  11  16   4   8  12   1   5   9  13
  15   3   7  11  16   4   8  12   1   5   9  13   2   6  10  14
  16   4   8  12   1   5   9  13   2   6  10  14   3   7  11  14

What I would like to knowis how to get every single number and store them in the array, or even better in 2D array.

Might this help:http://www.leepoint.net/notes-java/data/arrays/arrays-2D.html
[edit] answering the titles question
try this:

Object object...... 
int i =Integer.parseInt( object.toString() );

Might this help:http://www.leepoint.net/notes-java/data/arrays/arrays-2D.html
[edit] answering the titles question
try this:

Object object...... 
int i =Integer.parseInt( object.toString() );

This actually gives me an error.

atjava.lang.NumberFormatException.forInputString(NumberFormatException.java:65)/CODE]

[code]
int i = Integer.parseInt(puzzle.toString().substring(11));
	  	System.out.println(i);

I think it because puzzle.toString also have spaces. is there any way to fix it?
or to store every single number in the array

puzzle.toString().substring(11)

What is the String that is returned by that call to substring?
For debugging, get that String into a separate String variable and print it out so you can see what the program is doing.
Be sure to add delimiters on each side of the String so you can see if it has any spaces in it. ">" + theString + "<"

I assume he's reading the lines instead of int's.
just use the split method of the String class, you'll get an array of Strings which you can easily convert

This actually gives me an error.
atjava.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
int i = Integer.parseInt(puzzle.toString().substring(11));
System.out.println(i);

I think it because puzzle.toString also have spaces. is there any way to fix it?
or to store every single number in the array

Also could you not use the trim method on your string to take away all white/blank spaces?

trim only removes the leading and tailing spaces, not the ones in between.
if he uses split with space as separator, I don't think he'll need to go that far anyway.

trim only removes the leading and tailing spaces, not the ones in between.
if he uses split with space as separator, I don't think he'll need to go that far anyway.

oooh wow learnt something new :D havent used trim much...

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.