以下程式是"輸入10個數值,放入陣列中,並做排序" String S1; Integer sort[] = new Integer[10]; for (int i=0;i { S1 = JOptionPane.showInputDialog("請輸入一個整數進行排序:"); sort[i] = Integer.parseInt(S1); } Arrays.sort(sort); //利用Arrays.sort做排序 for (int ary : sort) System.out.print(ary+" | ");
//利用Math.max()找出最大值 int temp = sort[0]; //使temp=第一個值 for (int i=0;i<sort.length;i++) temp = Math.max(temp, sort[i]); int max = temp; System.out.println("\n最大值= "+max);
Q1 執行順序是?
Q2 如果我不想只設定成10個數字呢? 需要改哪裡讓程式為彈性?(意思是輸入多少個數字都可以)
This entry passed through the Full-Text RSS service — if this is your content and you're reading it on someone else's site, please read the FAQ at fivefilters.org/content-only/faq.php#publishers.
You are receiving this email because you subscribed to this feed at blogtrottr.com.
留言列表