欢迎来到天天文库
浏览记录
ID:12403152
大小:91.00 KB
页数:9页
时间:2018-07-16
《浙大《java语言程序设计》编程答案4》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、实验5分支结构程序的设计程序填空,不要改变与输入输出有关的语句。一、显示两级成绩输入一个正整数repeat(02、cstaticvoidmain(String[]args){intri,repeat;intmark;Scannerin=newScanner(System.in);repeat=in.nextInt();for(ri=1;ri<=repeat;ri++){mark=in.nextInt();/*------------------*/if(mark<60)System.out.println("Fail");elseSystem.out.println("Pass");}}}二、找最小值输入一个正整数repeat(03、peat<10),做repeat次下列运算:输入四个整数,输出其中的最小值。例:括号内是说明输入3(repeat=3)12619010403020-1-3-4-5输出minis1(126190中的最小值是1)minis10(10403020中的最小值是10)minis-5(-1-3-4-5中的最小值是-5)importjava.util.Scanner;publicclassTest30002{publicstaticvoidmain(String[]args){intri,repeat;inta,b,c,d,min;Sca4、nnerin=newScanner(System.in);repeat=in.nextInt();for(ri=1;ri<=repeat;ri++){a=in.nextInt();b=in.nextInt();c=in.nextInt();d=in.nextInt(); /*------------------*/min=a;if(min>b)min=b;if(min>c)min=c;if(min>d)min=d;System.out.println("minis"+min);}}}三、求三角形的面积和周长输入一个正整数5、repeat(06、ter="+(int)(perimeter*100+0.5)/100.);System.out.println("Thesesidesdonotcorrespondtoavalidtriangle");例:括号内是说明输入2(repeat=2)553114输出area=7.15;perimeter=13.0Thesesidesdonotcorrespondtoavalidtriangleimportjava.util.Scanner;publicclassTest30003{publicstaticvoidmain(Stri7、ng[]args){intri,repeat;floata,b,c,area,perimeter,s;Scannerin=newScanner(System.in);repeat=in.nextInt();for(ri=1;ri<=repeat;ri++){a=in.nextFloat();b=in.nextFloat();c=in.nextFloat(); /*------------------*/if(a+b>c&&a+c>b&&b+c>a)//注意:复合条件的正确写法{s=(a+b+c)/2;area=(floa8、t)Math.sqrt(s*(s-a)*(s-b)*(s-c));perimeter=a+b+c;System.out.println("area="+(int)(area*100+0.5)/100.+";perimeter="+(int)(perimeter*100+0.5)/100.)
2、cstaticvoidmain(String[]args){intri,repeat;intmark;Scannerin=newScanner(System.in);repeat=in.nextInt();for(ri=1;ri<=repeat;ri++){mark=in.nextInt();/*------------------*/if(mark<60)System.out.println("Fail");elseSystem.out.println("Pass");}}}二、找最小值输入一个正整数repeat(03、peat<10),做repeat次下列运算:输入四个整数,输出其中的最小值。例:括号内是说明输入3(repeat=3)12619010403020-1-3-4-5输出minis1(126190中的最小值是1)minis10(10403020中的最小值是10)minis-5(-1-3-4-5中的最小值是-5)importjava.util.Scanner;publicclassTest30002{publicstaticvoidmain(String[]args){intri,repeat;inta,b,c,d,min;Sca4、nnerin=newScanner(System.in);repeat=in.nextInt();for(ri=1;ri<=repeat;ri++){a=in.nextInt();b=in.nextInt();c=in.nextInt();d=in.nextInt(); /*------------------*/min=a;if(min>b)min=b;if(min>c)min=c;if(min>d)min=d;System.out.println("minis"+min);}}}三、求三角形的面积和周长输入一个正整数5、repeat(06、ter="+(int)(perimeter*100+0.5)/100.);System.out.println("Thesesidesdonotcorrespondtoavalidtriangle");例:括号内是说明输入2(repeat=2)553114输出area=7.15;perimeter=13.0Thesesidesdonotcorrespondtoavalidtriangleimportjava.util.Scanner;publicclassTest30003{publicstaticvoidmain(Stri7、ng[]args){intri,repeat;floata,b,c,area,perimeter,s;Scannerin=newScanner(System.in);repeat=in.nextInt();for(ri=1;ri<=repeat;ri++){a=in.nextFloat();b=in.nextFloat();c=in.nextFloat(); /*------------------*/if(a+b>c&&a+c>b&&b+c>a)//注意:复合条件的正确写法{s=(a+b+c)/2;area=(floa8、t)Math.sqrt(s*(s-a)*(s-b)*(s-c));perimeter=a+b+c;System.out.println("area="+(int)(area*100+0.5)/100.+";perimeter="+(int)(perimeter*100+0.5)/100.)
3、peat<10),做repeat次下列运算:输入四个整数,输出其中的最小值。例:括号内是说明输入3(repeat=3)12619010403020-1-3-4-5输出minis1(126190中的最小值是1)minis10(10403020中的最小值是10)minis-5(-1-3-4-5中的最小值是-5)importjava.util.Scanner;publicclassTest30002{publicstaticvoidmain(String[]args){intri,repeat;inta,b,c,d,min;Sca
4、nnerin=newScanner(System.in);repeat=in.nextInt();for(ri=1;ri<=repeat;ri++){a=in.nextInt();b=in.nextInt();c=in.nextInt();d=in.nextInt(); /*------------------*/min=a;if(min>b)min=b;if(min>c)min=c;if(min>d)min=d;System.out.println("minis"+min);}}}三、求三角形的面积和周长输入一个正整数
5、repeat(06、ter="+(int)(perimeter*100+0.5)/100.);System.out.println("Thesesidesdonotcorrespondtoavalidtriangle");例:括号内是说明输入2(repeat=2)553114输出area=7.15;perimeter=13.0Thesesidesdonotcorrespondtoavalidtriangleimportjava.util.Scanner;publicclassTest30003{publicstaticvoidmain(Stri7、ng[]args){intri,repeat;floata,b,c,area,perimeter,s;Scannerin=newScanner(System.in);repeat=in.nextInt();for(ri=1;ri<=repeat;ri++){a=in.nextFloat();b=in.nextFloat();c=in.nextFloat(); /*------------------*/if(a+b>c&&a+c>b&&b+c>a)//注意:复合条件的正确写法{s=(a+b+c)/2;area=(floa8、t)Math.sqrt(s*(s-a)*(s-b)*(s-c));perimeter=a+b+c;System.out.println("area="+(int)(area*100+0.5)/100.+";perimeter="+(int)(perimeter*100+0.5)/100.)
6、ter="+(int)(perimeter*100+0.5)/100.);System.out.println("Thesesidesdonotcorrespondtoavalidtriangle");例:括号内是说明输入2(repeat=2)553114输出area=7.15;perimeter=13.0Thesesidesdonotcorrespondtoavalidtriangleimportjava.util.Scanner;publicclassTest30003{publicstaticvoidmain(Stri
7、ng[]args){intri,repeat;floata,b,c,area,perimeter,s;Scannerin=newScanner(System.in);repeat=in.nextInt();for(ri=1;ri<=repeat;ri++){a=in.nextFloat();b=in.nextFloat();c=in.nextFloat(); /*------------------*/if(a+b>c&&a+c>b&&b+c>a)//注意:复合条件的正确写法{s=(a+b+c)/2;area=(floa
8、t)Math.sqrt(s*(s-a)*(s-b)*(s-c));perimeter=a+b+c;System.out.println("area="+(int)(area*100+0.5)/100.+";perimeter="+(int)(perimeter*100+0.5)/100.)
此文档下载收益归作者所有