Java第一次业-回文素数.docVIP

  • 71
  • 0
  • 约7.51千字
  • 约 5页
  • 2017-03-09 发布于贵州
  • 举报
Java第一次业-回文素数

《Java语言》课程作业 第一次 题 目 第8题 学 院 计算机学院 专 业 班 别 学 号 姓 名 陈聪 2015年4月22日 一、课程题目 8、题目:回文素数 回文素数是指一个数同时为素数和回文数。例如:131是一个素数,同时也是一个回文数。数字313和757也是如此。编写程序,显示前100个回文素数,每行显示10个数并且准确对齐,如下所示: 2 3 5 7 11 101 131 151 181 191 313 353 373 383 727 757 787 797 919 929 … …. …. …. … … … … … …. [选题人数:3] 二、题目分析与设计 1、题目的需求:编写程序,显示前100个回文素数,每行显示10个数并且准确对齐。 2、制定对应程序的功能: 1 将2以后的素数挑选出来,直到显示完前100个回文素数:利用for循环。 2 判断挑选出来的素数是否为回文数:通过将原素数倒置再与原素数比较来判断。 3 输出回文素数,同时判断是否要换行,通过确定位数来使回文素数准确对齐。 3、 1 程序功能层次图: 程序结构流程图: N Y N Y N Y 4、所使用的开发环境:Eclipse 1 判断一个数是否为素数: i 2; while i a if a%i 0 continue outer; i++; 2 将素数倒置: s a;b 0; while s! 0 b b*10+s%10; s s/10; 3 判断素数是否为回文数并输出: if a b n++; if n%10 0 System.out.printf %8d\n,a ; else System.out.printf %8d,a ; 三、测试分析 1、题目的需求:编写程序,显示前100个回文素数,每行显示10个数并且准确对齐。因此本程序不需要构建测试数据。 2、运行程序的结果如下: 所得到的前一百个回文素数与预计结果一致,格式正确,每行显示10个数并且准确对齐。 附录:源代码 package hui; public class huiwen public static void main String args[] int a,b,s; int n 0,i; outer:for a 2;n 100;a++ //从2开始寻找为回文数的素数 i 2; while i a if a%i 0 continue outer; //判断一个数是否为素数 i++; s a;b 0; while s! 0 b b*10+s%10; s s/10; //将素数倒置赋给b if a b //判断素数是否为回文数 n++; if n%10 0 System.out.printf %8d\n,a ; //判断是否换行 else System.out.printf %8d,a ; 陈聪——《Java语言》课程作业 第一次 and actual case whether match; by is located land right nature; property status, whether has damage or quality problem; property using situation, rental or use; reference around similar property price, judge assessment value of rationality; whether exists property disputes, and seized, and freeze, and mortgage, and demolition, and transformation, limit situation. 2. to land right mortgage of, survey people should verified following information: land right card by contains Ming information right people, and location, and nature, and term, and area, and actual case whether match; land nature; land flat situation; ground buildings situation; reference around similar land pric

文档评论(0)

1亿VIP精品文档

相关文档