I try to write a program that displays the values of an array and that is composed of 2 classes.
One of these classes contains a method that uses System.out.print in a loop:
public class methodsForArray{
int numbers[];
public void printOutArray(){
for (int i=0; i<numbers.length; i++){
System.out.print(numbers[i]);
}
}
}
In the other class this method printOutArray() is applied:
public class application1{
public static void main(String[]args){
methodsForArray myObject=new methodsForArray();
myObject.numbers[]={1,3,4};
myObject.printOutArray(); //Here i apply the method
}
}
This way of doing works to display Strings or integers. But why does it not work for arrays? And how could i fix the program? Trying compile the class application1, results in following error message:
application1.java:5: error: not a statement
myObject.numbers[]={1,3,4};
^
application1.java:5: error: ';' expected
myObject.numbers[]={1,3,4};
^
application1.java:5: error: not a statement
myObject.numbers[]={1,3,4};
^
application1.java:5: error: ';' expected
myObject.numbers[]={1,3,4};
^
4 errors
Thanks.