测试输入: Java2实用教程 978-7-302-57544-3 65 486 预期输出: 书名:Java2实用教程 书号:978-7-302-57544-3 价格:65.0 页数:486 提示:每行输入一个数据,每个数据输出为一行用Java进行编程
时间: 2023-08-03 13:05:44 浏览: 151
以下是Java代码实现:
```
import java.util.Scanner;
public class Book {
private String name;
private String number;
private double price;
private int pages;
public Book(String name, String number, double price, int pages) {
this.name = name;
this.number = number;
this.price = price;
this.pages = pages;
}
public String getName() {
return name;
}
public String getNumber() {
return number;
}
public double getPrice() {
return price;
}
public int getPages() {
return pages;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String name = scanner.nextLine();
String number = scanner.nextLine();
double price = Double.parseDouble(scanner.nextLine());
int pages = Integer.parseInt(scanner.nextLine());
Book book = new Book(name, number, price, pages);
System.out.println("书名:" + book.getName());
System.out.println("书号:" + book.getNumber());
System.out.println("价格:" + book.getPrice());
System.out.println("页数:" + book.getPages());
}
}
```
输入数据后,输出结果为:
```
书名:Java2实用教程
书号:978-7-302-57544-3
价格:65.0
页数:486
```
阅读全文