This site requires JavaScript, please enable it in your browser!
Greenfoot back
CKL
CKL wrote ...

2012/11/1

How can I save the world into text file and load it again

1
2
darkmist255 darkmist255

2012/11/5

#
I would just use int a = Integer.parseInt(thirdLine.substring(0, indexOf(" "))); tempString = thirdLine.subString(indexOf(" "), thirdLine.length()); int b = Integer.parseInt(tempString.subString(0, indexOf(" "))); and so on...
danpost danpost

2012/11/5

#
I came up with the following (which each element in the new array can be assigned to a, b, c, d, e, and f accordingly):
String inLine = "0 5 0 3 0 0";
int[] nums = new int[6];
for (int i = 0; i < 6; i++)  nums[i] = Integer.valueOf("" + inLine.charAt(i * 2));
CKL CKL

2012/11/5

#
It shows it can't find a method call charAt.....
danpost danpost

2012/11/5

#
Please supply the code you are using.
CKL CKL

2012/11/5

#
Its all ok now, I have just fixed it, thx for your help so much~~ And also thanks to the others that help me a lot.
danpost danpost

2012/11/5

#
'array' is not a String variable, but an array of String variables. Line 6 should be:
for (int i = 0; i < 6; i++) set[i] = Integer.valueOf("" + lines.charAt(i * 2));
CKL CKL

2012/11/5

#
Yes, i have just discovered it -.-
CKL CKL

2012/11/5

#
But why cant I just type
for (int i = 0; i < 6; i++) set[i] = Integer.valueOf("" + lines.charAt(i ));  //<-- use i instead of i*2
danpost danpost

2012/11/5

#
You cannot use that because you have spaces between each number in the string. The first 6 characters of your string are "0 5 0 ", which is not what you need.
CKL CKL

2012/11/5

#
Oh I see, thank you
You need to login to post a reply.
1
2