sub class
public class Exer2
{
public void setLength(int x)
{
this.listLength=x;
}
public int getLength()
{
return this.listLength;
}
int listLength=getLength();
int list[]=new int[listLength];
public void display()
{
System.out.println("The array length is: "+list.length+" ");
}
}
main class
import java.util.*;
public class Output
{
static Exer2 r=new Exer2();
public static void main(String[]args)
{
Scanner input=new Scanner(System.in);
int temp;
System.out.println("Enter array length: ");
temp=input.nextInt();
r.setLength(temp);
r.display();
}
}
I have a problem about inputting the array length.
the array length is always 0. no matter what number i input.
the length always remains to 0.
I am sure that my codings are correct, im just confused why it always displays 0.
any help is highly appreciated. thanks in advance.
Sample Output:
Enter array length:
100
The array length is: 0