Как правильно использовать для цикла в реестре классов? - PullRequest
0 голосов
/ 10 ноября 2019

Мне было поручено создать программу, в которой пользователь мог бы вводить студентов по разделам в целом университете (каждый курс). Кажется, я не могу отобразить введенные пользователем значения в цикле 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 нулей)

1 Ответ

0 голосов
/ 10 ноября 2019

Измените эту строку:

name[srt] = input.nextLine();

на:

name[x] = input.nextLine();

...