Alright so I've created an array of type int with size 10.
I've initialized it to random values between 1-100.
Now my task is to write a method named output which will take an int array as a parameter and displays all elements of the array in a column like this:
Output
arr[0] : 17
arr[1] : 42
etc etc, but when I do it in eclipse it says
i cannot be resolved to a variable,
so I was thinking of re-initializing it in my method, but wouldn't that give me a whole set of different numbers?
private int [] nums;
public UsingArrays(){
nums = new int [10];
for (int i = 0; i <nums.length; i++){
nums[i] = (int)(Math.random()*100)+1;
}
}
public String Output(){
String string;
string = "Arr[" + i + "]:" + nums[i];
return string;
}
}
ivariable declared as object property?iinOutput()? you are missing a loop around it as well