java语句代码:接收输入的图书信息,输入图书的书名,图书定死为3本
时间: 2024-05-02 18:19:21 浏览: 45
Sure, I can help you with that! Here's a code snippet in Java for receiving input of book information, including the book title. For the purpose of this example, let's assume that three books are being added.
```
import java.util.Scanner;
public class BookInput {
public static void main(String[] args) {
String[] titles = new String[3];
Scanner scanner = new Scanner(System.in);
System.out.println("Please enter the book titles:");
for (int i = 0; i < 3; i++) {
titles[i] = scanner.nextLine();
}
System.out.println("You entered the following book titles:");
for (String title : titles) {
System.out.println(title);
}
scanner.close();
}
}
```
Hope that helps! Let me know if you have any other questions.
阅读全文