1. 程式人生 > >任意輸入10個int類型數據,排序輸出,找出素數

任意輸入10個int類型數據,排序輸出,找出素數

含義 ava ++ lse main \n void tin str

package 排序;

import java.util.Arrays;

public class Yh {
public static void main(String[] args)
{
int a[]= {1,17,24,21,7,9,8,10,3,14};
Arrays.sort(a);
System.out.print("排序輸出:");
for(int m=0;m<10;m++)
System.out.print(" "+a[m]);
System.out.print("\n");
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;
else
System.out.print(" "+a[i]);
}
System.out.println();
}
}

實驗心得:

1:通過本次實驗掌握了如何排序輸出

2:更加熟悉了對素數含義的理解

任意輸入10個int類型數據,排序輸出,找出素數