按照题目要求该如何改下面这段代码,这种没有任何结束条件的该如何跳出循环走外面的程序?希望有详细解说!
import java.util.Scanner;
public class oj1632 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int d=1;
while(sc.hasNext()){
Book b1=new Book(sc.next(),sc.nextDouble(),sc.nextInt());
System.out.println("现有图书信息:");
System.out.print("书号:"+d);
d++;
b1.put();
System.out.println();
}
sc.close();
}
}
class Book{
String name;
double price;
int qt;
public Book(String name,double price,int qt){
this.name=name;
this.price=price;
this.qt=qt;
}
public void put(){
System.out.println("书名:"+name+" 价格:"+price+"元 "+qt+"册");
}
}
18