- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
Java实验课经典题型加代码答案
Java实验课经典题型加程序代码
求出2-1000内的所有个位为3或7的素数,并按每行5列的格式输出。
package first_work;
public class First_work public static void main String[] args int i,m;
int j 0; for i 2;i 1000;i++ for m 2;m Math.sqrt i ;m++ if i%m 0 break; if m Math.sqrt i i%10 3||i%10 7 System.out.print i+ ; j++; if j! 0j%5 0 System.out.println ; ; 教材71页15题,增加以下内容:同时要求用选择排序、冒泡排序、插入排序实现,分别用不同的函数实现。
package first_work;
public class Sort public static void choose int[] x for int i 0; i x.length;i++ int lowerIndex i; for int j i+1;j x.length;j++ if x[j] x[lowerIndex] lowerIndex j; int temp x[i]; x[i] x[lowerIndex]; x[lowerIndex] temp; public static void insert int[] x for int i 1;i x.length;i++ for int j i;j 0;j-- if x[j] x[j-1] int temp x[j]; x[j] x[j-1]; x[j-1] temp; public static void main String[] args int[] a 20,10,55,40,30,70,60,80,90,100 ;
int i,j,x,T 0;
for i 1;i 10;i++ for j 0;j 9;j++ if a[j] a[j+1] T a[j]; a[j] a[j+1]; a[j+1] T; for x 0;x 10;x++ System.out.print ; System.out.print a[x] ; System.out.print \n ;
choose a ;
for x 0;x 10;x++ System.out.print ; System.out.print a[x] ; System.out.print \n ;
insert a ;
for x 0;x 10;x++ System.out.print ; System.out.print a[x] ; 实现一个三行三列的矩阵和它的转置相加。
package first_work;
public class Matrix public static void main String[] args int [][]array 1, 2, 3 , 4, 5, 6 , 7, 8, 9 ; int i, j, t; int count 0; for i 0; i 2; i++ for j i + 1; j 3; j++ t array[i][j]; array[i][j] array[j][i]; array[j][i] t; for i 0; i 3; i++ for j 0; j 3; j++ System.out.print array[i][j] + ; count++; if count! 0count%3 0 System.out.println ; for i 0; i 3; i++ for j 0; j 3; j++ System.out.print array[i][j] + array[j][i]+ ; count++; if count! 0count%3 0 System.out.println ; 建立交通工具类TransTool,里面包含两个方法void run 和void brake ,然后建立它的Bike、Car以及Bus子类, 在各个子类中重写void run 和void brake 方法,在实现各个方法时只要输出一个自己定义的对应的提示信息即可。最后建立一个测试类MyTest, 该类中包含主函数,测试运行时的多态性。
package yao2;
public class MyTest public static void main String[] args
文档评论(0)