Re: Need help with arrays
I think I might have figured it out. Am I just missing a () after numbers.length?
My second question though is, is this how you build an array? I dont have any notes on it or could I find any good tuts online.
private int[] buildArray(String line) {
int[]arr = new int[line.length()];
arr[0] = 0;
for (int i = 1; i < line.length(); i++){
arr[i] = Character.digit(line.charAt(i),10);
}
return arr;
}
Re: Need help with arrays
Please use code tags when posting code
Quote:
I think I might have figured it out. Am I just missing a () after numbers.length?
Don't just guess an answer and ask us to check if it is correct. Does it now compile and run, if so you have figured it out?
Hint: The answer is NO.
'i' is declared in the for statement and so is only visible in the for statement and its code block. However you have put a semi-colon after the for loop which terminates the code black and so the code following the semi-colon has nothing to do with the for loop.
BTW you may want to consider if you really want the for loop to continue whilst 'i' is greater than the length of the number array.
Quote:
My second question though is, is this how you build an array?
Again, it is up to you to compile it, run it and see what the output is. If you can't get it to work feel free to ask for help.