




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、diyi道编程题库:1、编写程序,计算下列分段函数的值。 x (x=0) y= -x (x=0) y=x; else y=-x; System.out.println(y=+y); 2、根据年龄,判断某人是否为成年。import java.io.*;public class testa public static void main(String args) throws IOExceptionint x; InputStreamReader reader=new InputStreamReader(System.in); BufferedReader input=new BufferedRe
2、ader(reader); System.out.println(请输入x:); String temp=input.readLine(); x = Float.parseFloat(temp); if(x=18) System.out.println(成年人); if(xy) m=x;else m=y; System.out.println(最大数为+m); 5、比较两个数的大小,找出其中的最小数并输出。import java.io.*;public class kapublic static void main(String args) throws IOExceptionfloat x,
3、y,m; m=0; InputStreamReader readerx=new InputStreamReader(System.in); BufferedReader inputx=new BufferedReader(readerx); System.out.println(请输入x:); String tempx=inputx.readLine(); x = Float.parseFloat(tempx); InputStreamReader readery=new InputStreamReader(System.in); BufferedReader inputy=new Buffe
4、redReader(readery); System.out.println(请输入y:); String tempy=inputy.readLine(); y= Float.parseFloat(tempy); if(xy) m=x;else m=y; System.out.println(最小数为+m); 6、编写一个Java程序,判断某年份是否为闰年。import java.io.*;public class testa public static void main(String args) throws IOExceptionfloat x; InputStreamReader re
5、ader=new InputStreamReader(System.in); BufferedReader input=new BufferedReader(reader); System.out.println(请输入x:); String temp=input.readLine(); x =Float.parseFloat(temp); if(x%400=0) System.out.println(+x+是闰年); else if(x%4=0) System.out.println(+x+是闰年); else System.out.println(+x+不是闰年); 7、比较两个数的大小,
6、找出其中的最大数和最小数并输出。import java.io.*;public class kapublic static void main(String args) throws IOExceptionfloat x,y; InputStreamReader readerx=new InputStreamReader(System.in); BufferedReader inputx=new BufferedReader(readerx); System.out.println(请输入x:); String tempx=inputx.readLine(); x = Float.parseF
7、loat(tempx); InputStreamReader readery=new InputStreamReader(System.in); BufferedReader inputy=new BufferedReader(readery); System.out.println(请输入y:); String tempy=inputy.readLine(); y= Float.parseFloat(tempy); if(xy) System.out.println(最小数为+x); System.out.println(最大数为+y); else System.out.println(最小
8、数为+y); System.out.println(最大数为+x); 8、比较两个数的大小,找出其中的最大数和最小数,并输出最大数和最小数之差。import java.io.*;public class kapublic static void main(String args) throws IOExceptionfloat x,y,m; InputStreamReader readerx=new InputStreamReader(System.in); BufferedReader inputx=new BufferedReader(readerx); System.out.printl
9、n(请输入x:); String tempx=inputx.readLine(); x = Float.parseFloat(tempx); InputStreamReader readery=new InputStreamReader(System.in); BufferedReader inputy=new BufferedReader(readery); System.out.println(请输入y:); String tempy=inputy.readLine(); y= Float.parseFloat(tempy); if(x0) y= 0 (x=0) -x (x0) y=x;
10、if(x=0) y=0; if(x1) y= 0 (-1x1) x+10 (x1) y=x-1; if(1.0=x&x=-1.0) y=0; if(x-1) y=x+10; System.out.println(y=+y); 第er道编程题库:1、编写一个Java程序在屏幕上输出“Hello!”。 public class test public static void main(String args) System.out.println(Hello!); 2、编写一个Java程序在屏幕上输出“Hello, world!”。 public class test public static
11、void main(String args) System.out.println(Hello,world); 3、编写一个Java程序在屏幕上输出“This is java!”。public class test public static void main(String args) System.out.println(This is java!); 4、编写一个Java程序在屏幕上输出“This is my program!”public class test public static void main(String args) System.out.println(This is
12、 my program!); 5、编写一个Java程序在屏幕上输出“How are you?”public class test public static void main(String args) System.out.println(How are you?); 6、编写一个圆类Circle,该类拥有:一个成员变量Radius(私有,浮点型); / 存放圆的半径;两个构造方法 Circle( ) / 将半径设为0 Circle(double r ) /创建Circle对象时将半径初始化为rclass Circle private double Radius; Circle() Radi
13、us=0.0; public Circle(double r) this. Radius= r; 7、定义一个表示学生信息的类Student,要求如下:(1)类Student的成员变量:sNO表示学号;sName表示姓名;sSex表示性别;sAge表示年龄;sJava:表示Java课程成绩。(2)类Student的方法成员:getNo():获得学号; getName():获得姓名; class Student private String sNO; private String sName; private char sSex; private int sAge; private int sJ
14、ava; public Student(String sNo, String sName) this.sNo = sNo; this.sName = sName; public String getsNo() return sNo; public String getsName() return sName; 8、定义一个表示水果的类Fruit,要求如下: (1)类的成员变量: fName表示水果名称,fColor表示水果颜色。 (2)类的成员方法:getName( ):获得水果名称。 class Fruit private String fName; private String fColo
15、r; public Fruit(String fName, String Fcolor ) this.sName = sName; this.fColor = fColor; public String getfName() return fName; 9、先定义一个类A(该类有成员变量x和y),再定义类A的子类B(要求B新增成员变量z)。class A private int x; private int y; public A(int x,int y ) this.x = x; this.y = y; class B extendsA private int z; public B(int
16、 z) this.z=z; 10、先定义一个类A(该类有成员变量x,成员方法f1( )对x赋初值),再定义类A的子类B(要求B新增成员变量y,新增成员方法f2( )对y赋初值)。class A private int x; public A(int x, ) this.x = x; public int f1x() return x; class B extendsA private int y; public B(int z) this.y = y; public int f2y() return y; 第三道编程题库:编写程序,实现1到100之间整数的累加并输出运算结果。 public c
17、lass a public static void main(String args) int i,s=0; for(i=1;i=100;i+) s=s+i; System.out.println(1到100的累加和是+s); 2、编写程序,计算1100中奇数的累加和并输出。public class a public static void main(String args) int i,s=0; for(i=1;i=100;i+) if(i%2!=0) s=s+i; System.out.println(1到100的奇数累加和是+s); 3、编写程序,计算1100中偶数的累加和并输出。 pu
18、blic class a public static void main(String args) int i,s=0; for(i=1;i=100;i+) if(i%2=0) s=s+i; System.out.println(1到100的偶数累加和是+s); 4、编写程序,计算10的阶乘并输出运算结果。public class a public static void main(String args) int i,s=1; for(i=1;i50) s=s+1-i; break; System.out.println(从1开始的累加和小于50的累加和是+s); 6、编写程序,计算偶数2、
19、4、6.的累加和,条件是和小于50。 public class a public static void main(String args) int i=1,s=0; label: while(true) s=s+2*i; i+; if(s50) s=s-2*i+2*1; break; System.out.println(从2开始的偶数累加和小于50的累加和是+s); 7、编写程序,输出下列图案: * * * * public class a public static void main(String args) int i,k; for(i=1;i=4;i+) for(k=1;k=2*i
20、-1;k+) System.out.print(*); System.out.println(); 8、编写程序,输出下列图案: * * * * public class a public static void main(String args) int i,j,k; for(i=1;i=4;i+) for(j=1;j=8-2*i;j+) System.out.print( ); for(k=1;k=2*i-1;k+) System.out.print(*); System.out.println(); 9、编写程序,输出下列图案: * * * * public class a public
21、 static void main(String args) int i,j,k; for(i=1;i=4;i+) for(j=1;j=2*i-2;j+) System.out.print( ); for(k=1;k=9-2*i;k+) System.out.print(*); System.out.println(); 10、编写程序在终端打印1100之间的素数。 public class a public static void main(String args) int i,j; label: for(i=2;i=100;i+) for(j=2;ji;j+) if(i%j=0) cont
22、inue label; System.out.print(+i); System.out.println(); 11、编写一个java程序,用穷举法找出250之间的素数,并打印出来。 public class s public static void main(String args) int i,j,k ; boolean flag ; for (i=2;i=50 ;i+ ) flag =true ; k=i/2 ; for (j=2;j=y) t=x; else t=y; return t; public static void main(String args) double x,y,m
23、; x=549.265; y=56.28; m =Max(x,y); System.out.println(最大数是+m); System.out.println(x=+x+y=+y); if(m=x&y=m) System.out.println(ture); else System.out.println(flase); 13、编写一自定义方法,找出两个数中的最小数,并main方法中验证。 public class astatic double Min(double x,double y) double t; if(x=y) t=x; else t=y; return t; public static void main(String args) double x,y,m; x=245.38; y=525.63; m =Min(x,y); System.out.println(最小数是+m); System.out.println(x=+x+y=+y); if(m=m) System.out.println(ture); else System.out.println(flase)
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 林业审批管理办法
- 库房物资管理办法
- 扬州造价管理办法
- 旅游栈道管理办法
- 技能中心管理办法
- 征兵补助管理办法
- 弃置暂行管理办法
- 教育游戏化在职业教育中培养学生的创新能力的实践探索报告
- 无锡食堂管理办法
- 收银权限管理办法
- 宗教数字化治理体系-洞察及研究
- 2024年云南省西盟佤族自治县人民医院公开招聘医务工作人员试题带答案详解
- 专项债申报操作流程及项目评审细则(详细版)
- 2025至2030中国电子产品散热器行业市场现状分析及竞争格局与投资发展报告
- 北师大版二年级下册口算题大全(全册完整) (一)
- JJG 667-2025液体容积式流量计检定规程
- 车间包装质量培训
- 2024年福州国企招聘笔试真题
- 普陀区2024-2025学年下学期期末考试六年级数学试卷及答案(上海新教材沪教版)
- 火场排烟消防课件
- 纺织检测公司管理制度
评论
0/150
提交评论