0
我試圖瞭解其中陣列可用於各種方式,我發現在本書的例子,我想修改我的陣列正在取得和我能夠創建數組對象引用變量的對象,但我不能夠在這裏讓用戶輸入值是我的代碼:使用戶通過數組在我的類的變量中輸入輸入字符串。
class Information {
String author, title;
}
public class Books {
public static void main(String[] args) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter Number of Books: ");
int n = Integer.parseInt(bufferedReader.readLine());
Information myBooks[] = new Information[n];
for (int i = 0; i < n; i++) {
myBooks[i] = new Information();
}
for (int j = 0; j < n; j++) {
myBooks[j].author = bufferedReader.readLine();
myBooks[j].title = bufferedReader.readLine();
}
for (int k = 0; k < n; k++) {
System.out.println("author of " + myBooks[k].title + " is " + myBooks[k].author);
System.out.println();
}
}
}
我怎樣才能讓用戶輸入值myBooks [0] .author和myBooks [0] .title僞等。
也許可以考慮使用'Scanner'呢?我發現使用用戶輸入更容易,但這只是我的看法。 http://www.java-made-easy.com/java-scanner.html http://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html – Michael
@邁克爾我只是犯了一個愚蠢的錯誤,我糾正它顯然我也試過你的建議,掃描儀和bufferedReader都工作,Thanx! – Alok