import java.util.Scanner; public class Pxsushu {public static void main(String[] args) {// TODO Auto-generated method stubScanner s = new Scanner(System.in);int temp;//對數組事先聲明并創建10個空間int[] a = new int[10];//把輸入的數存儲為數組for (int i = 0; i < 10; i++) {a[i] = s.nextInt();}//排序for (int i = 0; i < 10; i++) {for (int j = i + 1; j < 10; j++) {if (a[i] > a[j]) {temp = a[i];a[i] = a[j];a[j] = temp;}}}//輸出結果for (int i = 0; i < 10; i++) {System.out.print(a[i] + " ");}System.out.println(" ");//輸出素數System.out.print("素數為:");for(int i=0;i<10;i++){if(a[i]==0 && a[i]==1)continue;else if(a[i]/2>1 && a[i]%2==0)continue;else if(a[i]/3>1 && a[i]%3==0)continue;else if(a[i]/5>1 && a[i]%5==0)continue;else if(a[i]/7>1 && a[i]%7==0)continue;elseSystem.out.print(" "+a[i]);}System.out.println();}}
實驗結果
心得體會:
? 通過本次程序設計,對冒泡排序有了進一步的掌握,將C語言中的學的冒泡排序應用到了JAVA程序語言的設計當中了。