close

fdggg sddsf fggg fdgdf dfgfg 

輸入人數,亂數取陣列值再排序輸入3ㄍ人 --->第1ㄍ先投1次.在.投完換第2ㄍ.然後再.換第3ㄍ第3ㄍ投完.又換第1ㄍ投....第1個人第一次5點 第2次6點 第3次4點5+6+4+....第2個人第一次4點 第2次3點 第3次6點4+3+6+....第3個人第一次5點 第2次4點 第3次6點5+4+6+....像上面這樣...而第3個人點數最先投到101.這時候第1ㄍ和第2個...分別投到97點和95點這時後就開始排列點數第1名ㄉ點數:101第2名ㄉ點數:97第3名ㄉ點數:95import java.io.*;import java.util.*;public class JavaHomeWork { public static void main(String[] args) throws IOException { int inInt[], man, tmp = 0, getR; Random r = new Random(); BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); System.out.print("請輸入人數:"); man = Integer.parseInt(in.readLine()); inInt = new int[man]; do { for (int i = 0; i < man; i++) { getR = r.nextInt(6) + 1; tmp = getR; inInt[i] = inInt[i] + tmp; tmp = inInt[i]; if (tmp > 100) break; } } while (tmp < 100); System.out.print("取得的資料:"); for (int i = 0; i < man; i++) { System.out.print(inInt[i] + ","); } System.out.print("\n排序後:"); inInt = bubble(inInt, inInt.length); for (int i = 0; i < man; i++) { System.out.print(inInt[i] + ","); } } public static int[] bubble(int a[], int n) { int i, j, temp; for (i = n - 1; i > 0; i--) { for (j = 1; j <= i; j++) { if (a[j - 1] < a[j]) { temp = a[j - 1]; a[j - 1] = a[j]; a[j] = temp; } } } return a; }}執行結果:請輸入人數:10取得的資料:101,86,77,100,80,61,63,71,78,61,排序後:101,100,86,80,78,77,71,63,61,61, .msgcontent .wsharing ul li { text-indent: 0; } 分享 Facebook Plurk YAHOO!

 

好站連結:http://tw.myblog.yahoo.com/edison573633

























arrow
arrow
    全站熱搜
    創作者介紹
    創作者 hglfseaupj 的頭像
    hglfseaupj

    干脆利落

    hglfseaupj 發表在 痞客邦 留言(0) 人氣()