Q: I want to read an array but when i press the play button nothing happens! what it is wrong with my code? i have a problem with scanner! i don't know why i can't read the array.
import java.util.Scanner;

public class hotel {

    public static void main(String[] args) {
        String []name = new String[10]; //first array
        double [][]money = new double[12][2];//second array 
        Scanner input = new Scanner(System.in);
        for(int i=0; i<10; i++) {
            name[i] = input.next(); //here is my problem
        }
        for(int k=0; k<12; k++) {
            for(int j=0; j<12; j++) {
                if ((j==1)||(j==2)||(j==10)) {
                    money[k][j]=-1;
                }
                else {
                    money[k][j]= input.nextDouble(); //and here 
                }
            }
        }
    }
}


A: In your loop you're accessing money[12][2] which doesn't exists since you declared money as new double[12][2]. I suspect you might wanted to create money as double[] money = new double[12][12];
