首页 > 其他 > 详细

实验五

时间:2019-04-07 13:50:19      阅读:111      评论:0      收藏:0      [点我收藏+]

package paixu;

public class PaiXu {
public static void main(String[] args)
{
int a[]= {1,4,13,5,15,6,17,8,19,10};
int l;
for(int i=0;i<10;i++)
for(int j=0;j<9-i;j++)
if (a[j]>a[j+1]) {
l=a[j];
a[j]=a[j+1];
a[j+1]=l;
}
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();
}
}

 

 

实验结果

技术分享图片

 

实验心得:

    JAVA中数组一旦定义好就不能修改长度,如果要修改就必须重新定义一个新数组或者引用其他数组,它的灵活性较差。排序输出中用了冒泡排序,对此不是很熟练,需要加强练习。素数输出中通过借鉴其他同学的程序,使用了最基本最原始的方法,比其他方法更便于理解。

 

实验五

原文:https://www.cnblogs.com/1998bmx/p/10664964.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!