I want to print out my array in my Insertionsort
method, but it cannot find it. How do I make my array/variable accessible in all my methods? I am new to Java. Thanks.
import java.util.Arrays;
public class insertionsort {
public static void main(String[] args) {
UnsortedListPrintout();
Insertionsort();
}
public static void UnsortedListPrintout() {
int[] ul = new int[] {2, 5, 7, 3, 6, 10, 8, 7, 7, 1};
System.out.println("Unsorted List: " + Arrays.toString(ul));
}
public static void Insertionsort() {
System.out.println(ul[1]);
}
}
Error:
error: cannot find symbol
System.out.println(ul[1]);
^
symbol: variable ul
location: class insertionsort
1 error