I have an array:
private String[] gamesArray = new String[] {"spin", "tof"};
And when I start the program, I want the program to print the items in the array:
Please select a game: spin, tof.
This is my attempt:
import java.util.Scanner;
public class Main {
private Scanner console = new Scanner(System.in);
private Spin spin = new Spin();
private String input = "";
private String[] gamesArray = new String[] {"spin", "tof"};
public static void main (String[] args) {
System.out.println("Welcome to the system!");
for (String s : gamesArray) {
System.out.println("Please select a game:" + s);
}
}
}
Error:
src\Main.java:15: error: non-static variable gamesArray cannot be referenced fro
m a static context
for (String s : gamesArray) {
^
What is wrong?