Could you please elaborate on what you mean when you say "describe arrays with static methods"?
For time being, I am assuming that you want to see how to have an array as an instance variable and then print it using static methods.
For the above assumption, please find the code below.
CODE
public class Main {
private static int[] arr = new int[10000];
private static int size = 0;
public static void add(int el) {
if (size >= 10000) {
System.out.println("Array is already full!!");
}
arr[size ++] = el;
}
public static void print() {
for (int i=0; i<size; i++) {
System.out.print(arr[i] + " ");
}
System.out.println();
}
public static void main(String[] args) {
for (int i=1; i<=100; i++) {
add(i);
}
print();
}
}
Get Answers For Free
Most questions answered within 1 hours.