我被分配去做一个程序,用户可以在整个大学(每门课程)的每个部分输入学生。我似乎无法在for循环中显示用户输入的值,(我决定声明某个课程每年的数组)我只是java的新手,对不起,如果它不可读
String[] name1a = new String [2000];
System.out.println("\nDo you want to add students or view student?\nA.ADD\nB.DISPLAY");
System.out.println("Enter the letter of your choice");
view=input.next().charAt(0);
if (view=='a' || view=='A')
{System.out.println("\nThe following are the section/s for "+yearlvl.get(yrlvl-1));
for (int i = 0; i < Sections1a.size(); i++) {
System.out.println((i+1)+"."+Sections1a.get(i));
}//section names display
System.out.println("Enter the number of the section");
int picksection1a=input.nextInt()*60;
input.nextLine();
System.out.println("How many students do you want to add?");
int studnum1a=input.nextInt();
input.nextLine();
for (int counter=picksection1a; counter<(picksection1a+studnum1a); counter++)
{ System.out.println("Student #"+(counter+1)+": ");
name1a[counter]=input.nextLine();
}//for counter
}//if view A
else if (view=='B' || view=='b')
{ System.out.println("\nThe following are the section/s for "+yearlvl.get(yrlvl-1));
for (int i = 0; i < Sections1a.size(); i++) {
System.out.println((i+1)+"."+Sections1a.get(i));
}//section names display
System.out.println("Enter the number of the section");
int viewsection1a=input.nextInt()*60;
input.nextLine();
int dec=1;
for (int display=viewsection1a ; display<(viewsection1a+60); display++)
{
System.out.println("Student #"+dec+": "+name1a[display]);
//it only shows null, the values I inputted doesn't show up
}
}//else if view b
我希望程序显示60个值。 (我的意思是输入的值,其余60个空值)
答案 0 :(得分:0)
更改此行:
name[srt] = input.nextLine();
收件人:
name[x] = input.nextLine();