標題:
對陣列排序 (一)
[打印本頁]
作者:
tonyh
時間:
2020-2-4 14:40
標題:
對陣列排序 (一)
本帖最後由 tonyh 於 2020-2-4 14:53 編輯
假設有一陣列其內容為:
int n[]={34,65,7,-3,6546,-564,0,-11,90,123};
試運用 Arrays 類別中的 sort() 函式, 對該陣列排序.
import java.util.Arrays;
public class Ch42
{
public static void main(String args[])
{
int n[]={34,65,7,-3,6546,-564,0,-11,90,123};
System.out.println("排序前:");
for(int i=0; i<n.length; i++)
System.out.print(n[i]+" ");
System.out.println();
Arrays.sort(n);
System.out.println("排序後:");
for(int i=0; i<n.length; i++)
System.out.print(n[i]+" ");
}
}
複製代碼
import java.util.Arrays;
public class Ch30 {
public static void main(String args[]) {
int n[]={34,65,7,-3,6546,-564,0,-11,90,123};
System.out.println("排序前: ");
for(int i=0; i<n.length; i++)
System.out.print(n[i]+" ");
Arrays.sort(n);
System.out.println("\n排序後(遞增): ");
for(int i=0; i<n.length; i++)
System.out.print(n[i]+" ");
System.out.println("\n排序後(遞減): ");
for(int i=n.length-1; i>=0; i--)
System.out.print(n[i]+" ");
}
}
複製代碼
作者:
蔡承翰
時間:
2020-2-4 14:59
import java.util.Arrays;
public class Ch01 {
public static void main(String[] args) {
int n[]={34,65,7,-3,6546,-564,0,-11,90,123};
System.out.println("排列前: ");
for(int i=0;i<n.length;i++){
System.out.print(n[i]+" ");
}
System.out.println();
Arrays.sort(n);
System.out.println("排列後: ");
for(int i=0;i<n.length;i++){
System.out.print(n[i]+" ");
}
}
}
複製代碼
作者:
蘇行一
時間:
2020-2-4 14:59
import java.util.Arrays;
public class Ch1 {
public static void main(String[] args) {
int n[]={34,65,7,-3,6546,-564,0,-11,90,123};
System.out.println("排序前: ");
for(int i=0; i<n.length; i++)
System.out.print(n[i]+" ");
System.out.println();
Arrays.sort(n);
System.out.println("排序前: ");
for(int i=0; i<n.length; i++)
System.out.print(n[i]+" ");
}
}
複製代碼
作者:
張宸翔
時間:
2020-2-4 15:00
import java.util.Arrays;
public class Ch01 {
public static void main(String[] args) {
int n[]={34,65,7,-3,6546,-564,0,-11,90,123};
System.out.println("排序前: ");
for(int i=0; i<n.length; i++)
System.out.print(n[i]+" ");
System.out.println();
Arrays.sort(n);
System.out.println("\n排序後(遞增): ");
for(int i=0; i<n.length; i++)
System.out.print(n[i]+" ");
System.out.println();
System.out.println("\n排序後(遞減): ");
for(int i=n.length-1; i>=0; i--)
System.out.print(n[i]+" ");
System.out.println();
}
}
複製代碼
作者:
黃煜城
時間:
2020-2-4 15:01
import java.util.Arrays;
public class Ch20
{
public static void main(String args[])
{
int n[]={34,65,7,-3,6546,-564,0,-11,90,123};
System.out.println("排序前:");
for(int i=0; i<n.length; i++)
System.out.print(n[i]+" ");
System.out.println();
Arrays.sort(n);
System.out.println("排序後:");
for(int i=0; i<n.length; i++)
System.out.print(n[i]+" ");
}
}
複製代碼
作者:
盧弘毅
時間:
2020-2-4 15:03
import java.util.Arrays;
public class Ch50
{
public static void main(String[] args)
{
int n[]={34,65,7,-3,6546,-564,0,-11,90,123};
System.out.println("排序前: ");
for(int i=0;i<n.length;i++)
System.out.print(n[i]+" ");
System.out.println();
Arrays.sort(n);
System.out.println("排序後: ");
for(int i=0;i<n.length;i++)
System.out.print(n[i]+" ");
}
}
複製代碼
作者:
蘇宜貞
時間:
2020-2-4 15:03
import java.util.Arrays;
public class Ch01
{
public static void main(String[] args)
{
int n[]={53,642,-5,66,73,-26,0,896,-782};
System.out.println("排序前: ");
for(int i=0; i<n.length; i++)
System.out.print(n[i]+" ");
System.out.println();
Arrays.sort(n);
System.out.println("排序後: ");
for(int i=0; i<n.length; i++)
System.out.print(n[i]+" ");
}
}
複製代碼
作者:
楊秉樺
時間:
2020-2-4 15:03
import java.util.Arrays;
public class Ch37 {
public static void main(String[] args)
{
int n[]={34,65,7,-3,6546,-564,0,-11,90,123};
System.out.println("排序前: ");
for (int i=0;i<n.length;i++)
System.out.print(n[i]+" ");
System.out.println();
Arrays.sort(n);
System.out.println("排序後: ");
for (int i=0;i<n.length;i++)
System.out.print(n[i]+" ");
System.out.println();
}
}
複製代碼
作者:
邱翊博
時間:
2020-2-4 15:04
package po;
import java.util.Arrays;
public class po {
public static void main(String[] args) {
int n[]={34,65,7,-3,6546,-564,0,-11,90,123};
System.out.println("排序前:");
for(int i=0; i<n.length; i++)
System.out.print(n[i]+" ");
System.out.println();
Arrays.sort(n);
System.out.println("排序後:");
for(int i=0; i<n.length; i++)
System.out.print(n[i]+" ");
}
}
複製代碼
作者:
劉家銘
時間:
2020-2-4 15:04
import java.util.Arrays;
public class Ch30 {
public static void main(String[] args)
{
int n[]={34,65,7,-3,6546,-564,0,-11,90,123};
System.out.println("排序前:");
for(int i=0;i<n.length;i++)
System.out.print(n[i]+" ");
System.out.println();
Arrays.sort(n);
System.out.println("排序後:");
for(int i=0;i<n.length; i++)
System.out.print(n[i]+" ");
}
}
複製代碼
作者:
何蕙妘
時間:
2020-2-4 15:05
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Scanner;
public class Ch54 {
public static void main(String[] args) {
int n[]={34,65,7,-3,6546,-564,0,-11,90,123};
System.out.println("排序前: ");
for(int i=0;i<n.length;i++)
System.out.print(n[i]+" ");
System.out.println();
Arrays.sort(n);
System.out.println("排序後: ");
for(int i=0;i<n.length;i++)
System.out.print(n[i]+" ");
}
}
複製代碼
作者:
沙芃妘
時間:
2020-2-4 15:12
public class Ch42 {
public static void main(String[] args)
{
int n[]={34,65,7,-3,6546,-564,0,-11,90,123};
System.out.println("排序前:");
for(int i=0; i<n.length; i++)
System.out.print(n[i]+" ");
System.out.println();
Arrays.sort(n);
System.out.println("排序後");
for(int i=0; i<n.length; i++)
System.out.print(n[i]+" ");
}
}
複製代碼
作者:
陳梓瑜
時間:
2020-2-4 15:16
public class Ch5 {
public static void main(String[] args)
{
int n[]={34,65,7,-3,6546,-564,0,-11,90,123};
System.out.println("排序前:");
for(int i=0;i<n.length;i++)
System.out.print(n[i]+" ");
System.out.println();
Arrays.sort(n);
System.out.println("排序後:");
for(int i=0;i<n.length;i++)
System.out.print(n[i]+"");
}
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2