【发布时间】:2017-08-11 06:07:11
【问题描述】:
编写简历生成器。我被困在一个必须与每所学校相对应的描述部分,但用户输入却是可变的(用户确定每所学校有多少描述点)。每次我尝试从此循环打印时,都会收到一个错误,即找不到变量。如何解决?
输入学校的循环:
//numberOfSchools is int entered by user
for (int i = 0; i < numberOfSchools; i++) {
System.out.println("What was school " + (i + 1) + " name?");
schoolInfo[i][0] = scan.nextLine();
System.out.println("Where was " + schoolInfo[i][0] + " ?");
schoolInfo[i][1] = scan.nextLine();
System.out.println("What was your start date at " + schoolInfo[i][0]);
schoolInfo[i][2] = scan.nextLine();
System.out.println("What was your end date at " + schoolInfo[i][0] +
"enter 'present' if still attending");
schoolInfo[i][3] = scan.nextLine();
System.out.println("How many description points would you like to add for School" + i);
int eduDescAmount = scan.nextInt();
String eduDesc[][] = new String[numberOfSchools][eduDescAmount];
scan.nextLine();
for(int j = 0; j < eduDescAmount; j++){
System.out.println("Enter detail " + (j+1) + " for " + schoolInfo[i][0]);
eduDesc[i][j] = scan.nextLine();
}
}
打印循环:
for (int r = 0; r < schoolInfo.length; r++) {
for (int q = 0; q < schoolInfo.length; q++){
System.out.println(eduDesc[r][q]);
}
【问题讨论】:
-
您遇到了什么问题?
-
需要澄清您的问题。无法理解您需要什么。
-
需要更多代码说明。
标签: java arrays loops for-loop multidimensional-array