标签:创建 else == i++ tin void 结果 main lse
package jiangli; import java.util.Scanner; public class Paixu { public static void main(String[] args) { Scanner 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]==2||a[i]==3||a[i]==5||a[i]==7) System.out.print(a[i]+" "); if(a[i]>2) { if(a[i]%2!=0) { for(int j=3;j<Math.sqrt(a[i]);j+=2) { if(a[i]%j==0) break; else { System.out.print(" "+a[i]); break; } } } } } } }
运行结果:
99 45 24 4 8 7 53 3 72 1
1 3 4 7 8 24 45 53 72 99
素数是:3 7 53
标签:创建 else == i++ tin void 结果 main lse
原文地址:https://www.cnblogs.com/pblqjyg/p/10674116.html