バブルソートのコードなんですが、ネストされたfor文あたりがよく理解できません。
また初心者のためのこのようなコードで一般的につまずく人は少ないのでしょうか?
自分だけわけわからんじゃないかと思って不安です笑
import java.io.*; class practice1 { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int[] test = new int[5]; System.out.println(test.length + "人の点数を入力してください"); for(int i=0; i<test.length; i++) { String str = br.readLine(); test[i] = Integer.parseInt(str); } for(int s=0; s<test.length-1; s++) { for(int t=s+1; t<test.length; t++) { if(test[t] > test[s]) { int tmp = test[t]; test[t] = test[s]; test[s] = tmp; } } } for(int j=0; j<test.length; j++) { System.out.println((j+1) + "番目の点数は" + test[j] + "点です"); } } }
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/11/29 07:32
2016/11/29 07:36
2016/11/29 07:40
2016/11/29 07:41
退会済みユーザー
2016/11/29 07:51
2016/11/29 07:56
退会済みユーザー
2016/11/29 08:06
2016/11/29 12:24
2016/11/29 12:34