最后未打印2D阵列

时间:2018-10-12 03:14:12

标签: java arrays

开始在学校编写代码,但我似乎无法在最后打印我的数组。有什么建议么?我在打印2D阵列时有什么不同的选择?

import java.util.Scanner;
public class MyJavaLab04{
    public static void main(String[]args){
    Scanner sc = new Scanner(System.in);

    System.out.println("How many movie reviewers are going to enter 
    reviews?");
    int numNames = Integer.parseInt(sc.nextLine());

    String namesReviewers[] = new String[numNames];
        for(int x=0; x<namesReviewers.length; x++){
            System.out.println("Enter movie reviewer " + (x+1) + ":");
            namesReviewers[x] = sc.nextLine();
        }
    System.out.println("How many movies are going to be reviewed?");
    int movieNames = Integer.parseInt(sc.nextLine());

    String movieNamesArr[] = new String[movieNames];
        for(int y=0; y<movieNamesArr.length; y++){
            System.out.println("Enter movie " + (y+1) + ":");
            movieNamesArr[y] = sc.nextLine();
        }

    String movieReviews[][] = new String[numNames][movieNames];
        for (int x=0; x<namesReviewers.length; x++){
            for (int y=0; y<movieNamesArr.length; y++){
                System.out.println(namesReviewers[x] + " enter review for " + movieNamesArr[y] + ":");
                movieReviews[x][y] = sc.nextLine();
            }
        }    
        }
    }

0 个答案:

没有答案