2010年9月12日日曜日

二つ以上の数値の入力

import java.io.*;
class test
{
public static void main(String[] args) throws IOException
{
System.out.println("Enterで区切って整数を二つ入力して");

BufferedReader br =
new BufferedReader(new InputStreamReader(System.in));

String str1 = br.readLine();
String str2 = br.readLine();

int num1 = Integer.parseInt(str1); /* strを数値に変換してnum1に代入 */
int num2 = Integer.parseInt(str2); /* ↑と同じ */

System.out.println("最初に" + num1 + ",次に" + num2 + "が入力されました。");
}
}

0 件のコメント:

コメントを投稿