【发布时间】:2015-05-23 22:24:16
【问题描述】:
我想从扫描仪输入收集到的字符串,然后将它们放入 String[] 中,我遇到的问题是我找不到在几条语句中输入它们的方法。我不想有任何循环,因为我不想让要求名称的消息重复 20 次。我想将输入的 20 个名称(每个名称之间有一个空格)放入一个数组中的 20 个不同的空格中。
import java.util.Scanner;
public class Gradebook {
String[] lastName;
String[] firstName;
int[] ID;
int[][] testGrades;
int[][] hwGrades;
public Gradebook(String[] lastName, String[] firstName, int[] ID, int[][] testGrades, int[][] hwGrades){
Scanner input = new Scanner(System.in);
this.lastName = new String[20];
this.firstName = new String[20];
this.ID = new int[20];
this.testGrades = new int[20][5];
this.hwGrades = new int[20][5];
System.out.println("Enter last names of all people in alphbetical order: ");
// this was my attempt to input them:
lastName[] = input.next();
}
}
【问题讨论】: