How to make a static array in main method in java? -
i reading arrays in java , made code calculating number of appearances of numbers in array .
public class example { static int b[] = new int[13]; // can not static int b[] = new int[a.length] because a[] in not static array static int count = 0; public static void main(string[] args) { int[] = { 2, 3, 4, 3, 3, 5, 4, 10, 9, 1, 9, 11, 15 }; counting(a); printcount(); } private static void printcount() { int k = 0; (int = 0; < b.length; i++) { system.out.print("number" + " " + a[k] + " " + "is found" + " "); // here error in a[k] because not static , eclipse says : cannot resolved variable system.out.println(b[i] + " " + "times"); k++; } system.out.println(); } private static void counting(int[] a) { (int = 0; < a.length; i++) { (int k = 0; k < a.length; k++) { if (a[i] == a[k]) { b[i] = ++count; } } count = 0; } } }
i got stuck in printcount() method , there can not call a[] array in method because a[] not static in main method . tried write static int[] = { 2, 3, 4, 3, 3, 5, 4, 10, 9, 1, 9, 11, 15 };
in main method eclipse not accept . how can make a[] static array can reached in methods in example class above ?
thank you
public static void main(string[] args) { int[] = { 2, 3, 4, 3, 3, 5, 4, 10, 9, 1, 9, 11, 15 }; counting(a); printcount(a); }
pass array in printcount() method.