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程序语言的设计当中了。