実験課題2
Exercise 2(課題2) See the section 1.4.1. "About Standard Input and Output". Then show the execution result as the screenshot by creating Java project chapter1kadai2 with the following source codes. This program is similar to the program of the Fig. 57 that directly specifies the Scanner class by writing the package and class name joined by dot. The source code of Fig. 57 still can become shorter by using import keyword such as the following source code.
import java.util.*; // java.utilパッケージ内に含まれる全てのクラス等を読み込む(ソースコードの先頭からクラスブロックよりも前のどこかに記述する)
Scanner scan = new Scanner(System.in); // Scannerオブジェクトを作成する。
String input = scan.nextLine(); // 改行が押されるまでのテキストデータを返却する。
System.out.println("input: " + input);
(1.4.1.節をよく読み、以下のプログラムについて、プロジェクト名chapter1kadai2のJavaアプリケーションプロジェクトを作成して、実行結果を示しなさい。このプログラムは、Scannerクラスを参照するためにパッケージ名を直接記述して参照している図57のプログラムと同じプログラムである。次のように import文 を使って、パッケージをあらかじめ読み込むことで、パッケージ名による指定を省略している。)