標題:
對陣列排序 (一)
[打印本頁]
作者:
tonyh
時間:
2021-1-26 14:17
標題:
對陣列排序 (一)
假設有一陣列其內容為:
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]+" ");
}
}
複製代碼
作者:
劉凱閔
時間:
2021-1-26 14:42
import java.util.Arrays;
public class Ch10 {
public static void main(String[] args) {
int n[]={34,6,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]+" ");
}
}
複製代碼
作者:
吳聲寬
時間:
2021-1-26 14:43
import java.util.Arrays;
public class Ch11
{
public static void main(String[] args)
{
int n[]={34,65,7,-3,6546,-564,0,-11,90,123};
System.out.println("Before: ");
for(int i=0;i<n.length;i++)
System.out.print(n[i]+" ");
System.out.println();
Arrays.sort(n);
System.out.println("After: ");
for(int i=0;i<n.length;i++)
System.out.print(n[i]+" ");
}
}
複製代碼
作者:
李柏穎
時間:
2021-1-26 14:43
import java.util.Arrays;
public class Ch03
{
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 j=0; j<n.length; j++)
System.out.print(n[j]+" ");
}
}
複製代碼
作者:
卓炘暘
時間:
2021-1-26 14:45
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]+" ");
System.out.println();
System.out.println("排序後(遞減):");
for(int i=n.length-1; i>0; i--)
System.out.print(n[i]+" ");
}
}
複製代碼
作者:
藍健洲
時間:
2021-1-26 14:45
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]+" ");
}
}
複製代碼
作者:
王睿宇
時間:
2021-1-26 14:46
import java.util.Arrays;
public class A01 {
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+=1)
System.out.print(n[i]+"\t");
System.out.println();
Arrays.sort(n);
System.out.println("排序後(正)");
for(int i=0; i<n.length; i+=1)
System.out.print(n[i]+"\t");
System.out.println();
System.out.println("排序後(逆)");
for(int i=n.length-1; i>=0; i-=1)
System.out.print(n[i]+"\t");
}
}
複製代碼
作者:
楊小萱
時間:
2021-1-26 14:47
import java.lang.reflect.Array;
public class Ch05
{
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]+" ");
}
}
複製代碼
作者:
紀承典
時間:
2021-1-26 14:47
import java.util.Arrays
public class Ch01
{
public static void main(String[] args)
{
int n[]={34,65,7,-3,6546,-564,-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]+" ");
}
}
複製代碼
作者:
王博裕
時間:
2021-1-26 14:48
import java.util.Arrays;
public class Ch07 {
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();
}
}
複製代碼
作者:
楊澤全
時間:
2021-1-26 14:48
import java.util.Arrays;
public class Ch08
{
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-1;i++)
System.out.print(n[i]+" ");
System.out.println();
Arrays.sort(n);
System.out.println("排序後:");
for (int i=0;i<=n.length-1;i++)
System.out.print(n[i]+" ");
}
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2