




已阅读5页,还剩1页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、 试编写一个程序,将1500间能同时被2、5、7整除的数打印出来package ch3;public class M4 public static void main(String args)for(int i= 1; i=500; i+)if(i%2=0 & i%5=0 & i%7=0)System.out.println(i=+i); 2、 编写程序,根据考试成绩的等级打印出百分制分数段。设A为90分以上、B为80分以上、C为70分以上、D为60分以上、E为59分以下。要求在程序中使用开关语句。 public class M5 public static void main(String args) double num = 70.5;int x = (int)num;String result = ;switch(x/10)case 10:case 9: result=A; break;case 8: result=B; break;case 7: result=C; break;case 6: result=D; break;default: result=E;break;System.out.println(num+:+result);3、 编写程序,从10个数中找出最大值。public class M6 public static void main(String args) int a = new int7,4,2,1,0,9,6,5,3,8;for(int i =0; ia.length; i+)for(int j = i+1; ja.length;j+)if(ai max ) max = x;/System.out.println(max=+max);4、 编写程序,计算n的阶乘(n!),设n=10. public class M7 public static void main(String args) int n = 5;int sum = 1;for(int i = n;i1;i-)sum *= i;System.out.println(n+!=+sum);5、 编写程序,计算数学常数e的值,e=1+1/1!+1/2!+ .public class M8 public static void main(String args) double e = 1.0;for(int i = 1; i 1;i-)sum *= i;return sum;6、 编写程序,输出以下数据:N 10*N 100*N 1000*N1 10 100 10002 20 200 20003 30 300 30004 40 400 40005 50 500 5000 public class M9 public static void main(String args) System.out.println(Nt10*Nt100*Nt1000*N);for(int i= 1;i=5;i+)System.out.println(i+t+i*10+t+i*100+t+i*1000);7、编写程序,列出乘法口诀。public class M10 public static void main(String args) for(int i = 1;i=9; i+)for(int j = 1;j = i;j+)System.out.print(j+*+i+=+i*j+t);System.out.println();8、编写程序,输出1100间的所有奇数。public class M11 public static void main(String args) int x =1;for(int i = 1;i100;i+=2)System.out.println(i);9、(1)创建一个Rectangle类,添加两个属性width、height。 (2)在Rectangle中添加两个方法计算矩形的周长和面积。 (3)编程利用Rectangle输出一个矩形的周长和面积。public class M18 public static void main(String args)Rectangle r = new Rectangle(10,20);System.out.println(length:+r.getLength();System.out.println(area:+r.getArea();class Rectangleprivate double width;private double height;public double getWidth() return width;public void setWidth(double width) this.width = width;public double getHeight() return height;public void setHeight(double height) this.height = height;public Rectangle()public Rectangle(double width, double height)this.width = width;this.height = height;public double getLength()return 2*(width+height);public double getArea()return width*height;10、(1)设计一个Array类,添加一个整型数组,添加构造方法对数组赋初值。 (2)为Array类添加数组求和方法,添加返回求和的方法。 (3)编程利用Array计算数组的求和值并输出。public class M19 public static void main(String args) Array array = new Array(11,22,33);System.out.println(sum=+ array.getSum();class Arrayprivate int a;public Array(String str)String strings = str.split(,);a = new intstrings.length;for(int i = 0; istrings.length; i+)ai = Integer.parseInt(stringsi);private int sum()int s = 0;for(int x : a)s += x;return s;public int getSum()return sum();11、接口有什么作用?创建一个接口并在类中实现这个接口。package ch5;import java.util.ArrayList;import java.util.List;import ch5.service.Shape;import ch5.service.impl.Circle;import ch5.service.impl.Triangle;public class M13 public static void main(String args) Shape s1 = new Circle();Shape s2 = new Triangle();s1.draw();s2.draw();List list = new ArrayList();package ch5.service;public interface Shape public void draw();package ch5.service.impl;import ch5.service.Shape;public class Circle implements Shape Overridepublic void draw() System.out.println(画圆);package ch5.service.impl;import ch5.service.Shape;public class Triangle implements Shape Overridepublic void draw() System.out.println(画三角);12、如何创建一个自定义异常。public class M2 public static voi
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 鱼票月半出品课件细胞器
- 高铁物品安全知识培训课件
- 2025年度财务人员年末考核个人工作总结
- 高速公路路政管理
- 电脑钉钉显示课件已过期问题
- 电脑遥控专业知识培训班课件
- 电脑绘画兴趣课件
- 电脑知识培训课程目录课件
- 20kV及以下配网工程勘察设计合同
- 电脑基本知识培训班课件
- 2025年部编版道德与法治六年级上册全册教案设计(共4个单元含有教学计划)
- 焊工安全操作技术规范
- 医疗安全不良事件培训课件
- 《电子商务基础(第二版)》课件 第一章 电子商务概述
- 2025+CSCO结直肠癌诊疗指南解读
- 儿童体态课件
- 食堂从业人员培训内容
- 针灸学练习题库含答案
- 职业技术学院智能互联网络技术专业人才培养方案
- 悟空识字1-300(带拼音)-可打印
- DB14T 1736-2024医疗护理员服务规范
评论
0/150
提交评论