0
我有兩個類。我想打印對象的數組。這些對象具有屬性(其中一些屬性爲String
s),但是當程序將其讀取爲(nextLine)時,它將不會打印它。爲什麼我的程序不打印nextLine?
這裏是我的意思是:
public static void main(String[] args){
String auther,Title,genre;
int ISBN,publicationYear,ISBN2;
if (Book.getBookNo()< archive_size){
System.out.println("ISBN: ");
ISBN=scan.nextInt();
System.out.println("Auther: ");
auther=scan.nextLine(); //here is the problem if I choose next it's ok but no nextLine
scan.nextLine();
System.out.println("Published Year");
publicationYear=scan.nextInt();
System.out.println("Title: ");
Title=scan.nextLine();
scan.nextLine();
System.out.println("Genre: ");
genre=scan.next();
libraryBooks[Book.getBookNo()] = new Book(ISBN,auther,publicationYear,Title,genre);
}
public static void printAll(){
int i=0;
for (i=0 ; i<Book.getBookNo(); i++)
System.out.println("Book "+(i+1)+"\nISBN: "+libraryBooks[i].getISBN()+
"\nAuthor: "+libraryBooks[i].getAuther()+
"\npublishedyear: "+libraryBooks[i].getPublication()+"\nTitle: "+libraryBooks[i].getTitle()+
"\nGenre: "+libraryBooks[i].getGenre()+"\n");
}
這是有趣的我面對java的。它提醒了我過去的日子:) – Vipin