




已阅读5页,还剩4页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
显示hello java!public class Examplepublic static void main(String args)System.out.println(Hello Java!); 求圆的周长和面积public class Yuanpublic static void main(String args)double r=0,l=0,s=0;r=Double.parseDouble(args0);l=2*3.1415926*r;s=3.1415926*r*r;System.out.println(圆的周长为:+l);System.out.println(圆的面积为:+s); 计算一个给定底和高的直角三角形的斜边长public class Sanjiaoxingpublic static void main(String args)double base=0,height=0,length=0;base=Double.parseDouble(args0);height=Double.parseDouble(args1);length=Math.sqrt(base*base+height*height);System.out.println(三角形斜边为:+length); 求a+aa+aaa+.的和,其中a为1-9之间的整数,例如,当a=3、n=4时,求3+33+333+3333的和public class Test3_1public static void main(String args)int a=Integer.parseInt(args0);int n=Integer.parseInt(args1);int sum=0;int temp=0;for(int i=0;i0)n=m%10;m=m/10;System.out.println(n+ );i+;w=w*10; m=k;System.out.println(nDigital Number:+i);System.out.println(right Order:);w=w/10;while(w=1)n=m/w;System.out.println(n+ );m=m%w;w=w/10; 鸡和兔装在同一个笼子中,已知它们在一起一共有f只脚,h只头,求有多少只鸡和多少只兔public class Test3_3public static void main(String args)int f,h;int chicken,rabbit;f=Integer.parseInt(args0);h=Integer.parseInt(args1);if(f%2!=0|h%2!=0)System.out.println(The number of foot or head is wrong!);return; rabbit=f/2-h;chicken=h-rabbit;if(rabbit*4+chicken*2)!=f|(rabbit+chicken)!=h)System.out.println(The number of foot or head is wrong!);elseSystem.out.println(chicken:+chicken);System.out.println(rabbit:+rabbit); 判断素数的方法public class Test4_1public static void Test4_1(int n)int i;for(i=2;in/2) System.out.println(n+是素数);else System.out.println(n+不是素数); public static void main(String args)int n;n=Integer.parseInt(args0);Test4_1(n); 打印Fibonacci数列的方法public class Test4_2public static void Test4_2(int n)long f1=1,f2=1,f3;System.out.print(f1+ +f2);for(int i=2;in;i+) f3=f1+f2;f1=f2;f2=f3;System.out.print( +f2); public static void main(String args)int n;n=Integer.parseInt(args0);Test4_2(n); 计算xn的递归方法public class Test4_3public static long Test4_3(int x,int n)if(n=0) return 1;else return Test4_3(x,n-1)*x; public static void main(String args)int x,n;x=Integer.parseInt(args0);n=Integer.parseInt(args1);System.out.println(x+n+=+Test4_3(x,n); 编写数组的排序程序import java.io.*;public class BubbleSortpublic static void bubble(int a)int count=a.length,i;for(i=0;ii;j-)if(ajaj-1)int temp=aj;aj=aj-1;aj-1=temp; public static void main(String args)final int l=10;int a=new intl;for(int k=0;ka.length;k+)ak=(int)(100*Math.random();System.out.println(Before sort:);for(int i=0;ia.length;i+)System.out.print(ai+ );System.out.println();System.out.println(After sort:);bubble(a);for(int j=0;ja.length;j+)System.out.print(aj+ ); 编写折半查找的程序class Test5_2public static int bisearch(int a,int n)int low=0,high=a.length-1,mid=(low+high)/2;System.out.println(After sort:);for(int k=0;kahigh|nalow) return -1;while(lowmid)low=mid+1;high=high-1; elsehigh=mid-1;low=low+1; return -1;public static void sort(int a)int count=a.length,i;for(i=0;ii;j-)if(ajaj-1)int temp=aj;aj=aj-1;aj-1=temp; public static void main(String args)final int l=10;int a=new intl;int n,i;for(i=0;iargs.length-1;i+)ai=(int)(100*Math.random();n=Integer.parseInt(args0);sort(a);int place=bisearch(a,n);if(place!=-1)System.out.println(n+: +place);elseSystem.out.println(n+ is not found.);产生一个1-12之间的随机整数,并根据该随机整数的值,输出对应月份的英文名称class Test5_3public static void main(String args)Stringmonths=January,February,March,April,May,June,July,Argust,September,October,November,December;int n=(int)(1+Math.random()*12);System.out.println(monthsn-1); 建立包含10个字符串数据的一维数组,每个字符串数据的格式为“月月/日日/年年”,例如06/25/04,将每个日期采用类似“25th June 2004”的格式输出public class Test5_4public static void main(String args)Stringmonths=January,February,March,April,May,June,July,Argust,September,October,November,December;String suffix=1st,2nd,3rd;Stringdate=06/25/04,07/03/07,08/20/08,08/24/08,04/09/02,03/02/01,01/01/05,04/13/01,11/25/09,09/10/03;for(int i=0;idate.length;i+)Stringyear=20+datei.substring(6,8);int month=Integer.parseInt(datei.substring(0,2);int day=Integer.parseInt(datei.substring(3,5);if(day31) System.out.println(Day is illegal!); if(month0 & month0 & day=300&student.getSports()=96)|student.getTotal()School.getLine()System.out.println(student.getMessage()+accepted!);elseSystem.out.println(student.getMessage()+not accepted!);public static void main(String args)School school=new School(350);Student student1=new Student(Joseph,123,310,100);Student student2=new Student(Bill,456,351,80);Student student3=new Student(Herry,789,320,85);status(student1);status(student2);status(student3);求圆球的体积public class Squarepublic static void main(String args)double r=0,v=0;r=Double.parseDouble(args0);v=4*3.1415/3*r*r*r;System.out.println(圆球体积为:+v); 杨辉三角public class Yanghuipublic static void main(String args)int i,j;int a=new int 1111;for(i=1;i11;i+)aii=1;ai1=1; for(i=3;i11;i+)for(j=2;j=i-1;j+)aij=ai-1j-1+ai-1j;for(i=1;i11;i+)for(j=1;j=i;j+)System.out.print(aij+ );System.out.println(n); System.out.println(n);圆柱体class Circledouble x;double y;double r;Circle(double x,double y,double r)this.x=x;this.y=y;this.r=r; public void setX(double x)this.x=x; public void setY(double y)this.y=y; public void setR(double r)this.r=r; public double getX()return x; public double getY() return y; public double getR() return r; public double area()return r*r*3.1416; public double perimeter()return 2*r*3.1416; public void show()System.out.print(x=+x+,y=+y+,Radius=+r); public class Cylinder extends Circledouble h;Cylinder(double x,double y,double r,double h)super(x,y,r);this.h=h; public void setH(double h)this.h=h; public double getH()return h; public double area()return perime
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 情感共鸣与电动汽车品牌忠诚-洞察及研究
- 宠物智能识别系统-洞察及研究
- 2025年5月四川西南石油大学考试招聘事业编制辅导员15人考前自测高频考点模拟试题附答案详解(模拟题)
- 矿业权市场化配置与市场风险-洞察及研究
- 2025年德州平原县县属国有企业公开招聘工作人员模拟试卷及答案详解(全优)
- 中小企业财务预算管理实务
- 海洋气候变化监测技术-洞察及研究
- 信息技术和数学课堂整合案例申报
- 建筑工程项目成本控制实战案例分析
- 代码质量与软件可靠性-洞察及研究
- 人生的因拼搏而精彩课件
- 2025年国企综合笔试试题及答案
- 中药用药安全知识培训课件
- 重症胰腺炎护理查房
- 共青团入团团章知识考试题库300题(含答案)
- 老旧护栏加固施工方案
- 中国资源循环集团有限公司子公司招聘笔试题库2025
- 雨季行车安全培训
- 2025年青海海东通信工程师考试(通信专业实务终端与业务)高、中级考前题库及答案
- 露天煤业安全生产培训课件
- 2025年全国医学基础知识试题(附答案)
评论
0/150
提交评论