欢迎来到天天文库
浏览记录
ID:53847628
大小:855.84 KB
页数:39页
时间:2020-04-08
《java期末考试上机练习.docx》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、-----1.产生n个30以内的随机数,统计并输出1,2,3,各数段的数的个数,并输出数中的最大数和最小数。packagecom.zhang;importjava.util.Random;importjava.util.Scanner;publicclassDemo1{publicstaticvoidmain(String[]args){Scannersc=newScanner(System.in);intn=0,number;intarr[]=newint[31];intmaxNum=0,minNum=0;System.out.println("请输入
2、要产生的随机数的个数n:");n=sc.nextInt();for(inti=0;i0){if(num>maxNum){maxNum=num;}if(num3、数是:"+maxNum);System.out.println("产生的最小数是:"+minNum);}}2定义一个接口,接口中有四个抽象方法:求面积方法、求周长方法、显示面积方法及显示周长方法。定义Circle类和Rectangle类分别实现接口,在主类中实-----------现显示圆和矩形的面积和周长。packagecom.zhang;publicinterfaceTuxing{publicabstractvoidsetArea();publicabstractvoidsetGrith();publicabstractdoublegetArea()4、;publicabstractdoublegetGrith();}packagecom.zhang;-----------publicclassCricleimplementsTuxing{-----------doubler,grith,area;//r表示半径.grith是周长,area是面积-----------publicCricle(doubler){-----------this.r=r;-----------}@OverridepublicvoidsetArea(){-----------//TODOAut5、o-generatedmethodstubarea=Math.PI*r*r;}@OverridepublicvoidsetGrith(){//TODOAuto-generatedmethodstubgrith=2*r*Math.PI;}@OverridepublicdoublegetArea(){//TODOAuto-generatedmethodstubreturnarea;}@OverridepublicdoublegetGrith(){//TODOAuto-generatedmethodstubreturngrith;}-----------}pa6、ckagecom.zhang;-----------publicclassRectangledoubleheight,widthdoublegrith,area;implements;Tuxing{-----------publicthisthisRectangle(double.height=height;.width=width;height,doublewidth){-----------}-----------@OverridepublicvoidsetArea(){//TODOAuto-generatedmethodstubare7、a=height*width;}@OverridepublicvoidsetGrith(){//TODOAuto-generatedmethodstubgrith=2*(height+width);}@OverridepublicdoublegetArea(){//TODOAuto-generatedmethodstubreturnarea;}@OverridepublicdoublegetGrith(){//TODOAuto-generatedmethodstubreturngrith;}}packagecom.zhang;publicclassCeS8、hi{publicstaticvoidmain(String[]args){Cr
3、数是:"+maxNum);System.out.println("产生的最小数是:"+minNum);}}2定义一个接口,接口中有四个抽象方法:求面积方法、求周长方法、显示面积方法及显示周长方法。定义Circle类和Rectangle类分别实现接口,在主类中实-----------现显示圆和矩形的面积和周长。packagecom.zhang;publicinterfaceTuxing{publicabstractvoidsetArea();publicabstractvoidsetGrith();publicabstractdoublegetArea()
4、;publicabstractdoublegetGrith();}packagecom.zhang;-----------publicclassCricleimplementsTuxing{-----------doubler,grith,area;//r表示半径.grith是周长,area是面积-----------publicCricle(doubler){-----------this.r=r;-----------}@OverridepublicvoidsetArea(){-----------//TODOAut
5、o-generatedmethodstubarea=Math.PI*r*r;}@OverridepublicvoidsetGrith(){//TODOAuto-generatedmethodstubgrith=2*r*Math.PI;}@OverridepublicdoublegetArea(){//TODOAuto-generatedmethodstubreturnarea;}@OverridepublicdoublegetGrith(){//TODOAuto-generatedmethodstubreturngrith;}-----------}pa
6、ckagecom.zhang;-----------publicclassRectangledoubleheight,widthdoublegrith,area;implements;Tuxing{-----------publicthisthisRectangle(double.height=height;.width=width;height,doublewidth){-----------}-----------@OverridepublicvoidsetArea(){//TODOAuto-generatedmethodstubare
7、a=height*width;}@OverridepublicvoidsetGrith(){//TODOAuto-generatedmethodstubgrith=2*(height+width);}@OverridepublicdoublegetArea(){//TODOAuto-generatedmethodstubreturnarea;}@OverridepublicdoublegetGrith(){//TODOAuto-generatedmethodstubreturngrith;}}packagecom.zhang;publicclassCeS
8、hi{publicstaticvoidmain(String[]args){Cr
此文档下载收益归作者所有