アプリ版:「スタンプのみでお礼する」機能のリリースについて

入力データ数を入力して、その数だけ整数値を入力し配列を格納した後、入力した値を横に表示するプログラムを下記に作成したのですが、思う通りに表示されません。初期化しても最後の値になるし、なぜでしょうか?
import java.io.*;

class Hairetu1
{
public static void main(String args[]) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

System.out.print("データはいくつですか?");
String str = br.readLine();
int num = Integer.parseInt(str);

int a[]=new int[num];
int i,tmp=0;

for(i=0; i<a.length; i++){
System.out.print((i+1)+"番目は?");
str = br.readLine();
tmp = Integer.parseInt(str);
a[i] = tmp;
}
for(i=0; i<a.length; i++){
System.out.print("入力した値は"+tmp+"\t");
}

A 回答 (1件)

System.out.print( "入力した値は" + a[i] + "\t" );

    • good
    • 1

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!

このQ&Aを見た人はこんなQ&Aも見ています