实验五:任意输入10个int类型数据,排序输出,再找出素数

实验内容:任意输入10个int类型数据,排序输出,再找出素数

实验程序

public class bai {

public static void main(String[] args) {

Scanner s = new Scanner(System.in);

int temp;

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("素数是:")

实验结果

1 9 3 6 8 10 4 7

1 3 4 6 7 8 9 10

素数是:3 5 7

三.实验心得

对于素数的输出出现问题,不知道需要满足哪些条件,程序编写出错的地方较多,修改花了一些时间

posted @ 2019-04-07 20:36  嗯嗯¥  阅读(136)  评论(1编辑  收藏  举报