java程序填空题
一、程序填空题(每空3分,共30分)
1. 以下程序要求从键盘输入一个整数,判别该整数为几位数,并输出结果,请将下面的程序填写完整。
public class Blank1 { }
答案:(1)System.in (2)t=t/10
2. 在下面的程序中使用方法重载分别实现了两个和三个整数的相加,请将下面的程序填写完整。
class AddOver{ }
public class Blank2{ }
答案:(3)int add(int a,int b) (4)new AddOver()
3. 构造一个类来描述一个点,该类的构成包括点的x和y两个坐标,以及一些对点进行的操作,包括:取得点的坐标值,利用另一个点对当前点的坐标进行赋值,请将下面的程序填写完整。
class Point{
int x,y;
public (5) (int x, int y){
this.x=x; this.y=y;
public static void main(String[] args){ }
AddOver a= (4) ; System.out.println(a.add(1,2)); System.out.println(a.add(1,2,3)); public (3) { }
public int add( int a, int b, int c ){ }
return a+b+c ; return a+b;
public static void main(String[] args) throws IOException { }
Scanner sc=new Scanner( (1) ); int count=0,t; int x=sc.nextInt(); sc.close(); t=x;
while(t!=0){ }
System.out.println(x+\是\+count+\位数。\);
count++;
(2) ;
}
public Point getPoint(){ }
public void setPoint( (7) ){ } }
public static void main(String[] args){ }
Point a = new Point(3,4); Point b = new Point(0,0); b=a.getPoint();
Point c = new Point(0,0); c.setPoint(b); }
this.x=s.x; this.y=s.y; Point temp = new Point(0,0); temp.x=x; temp.y=y;
return (6) ;
public class Blank3 {
答案:(5)Point (6)temp
(7)Point s
4. 下面的程序完成从D:\\Hello.txt中读取文本并显示在屏幕上,请将下面的程序填写完整。
class Blank4 {
public static void main ( String[] args ) { String fileName = \, line; try {
BufferedReader in = new BufferedReader( (8) ); line = in.readLine(); while ( (9) ) {
System.out.println( line );
}
line = (10) ;
}
in.close();
catch (IOException e) {
System.out.println(\ + fileName ); } } }
答案:(8)new FileReader(fileName) (9)line!=null
(10)in.readLine()
5.下面的程序通过方法调用从包含7个学号的数组中随机抽取一个学号并输出显示,请将下面的程序填写完整。
public class Ex1 {
public (11) String getXh(){ } } }
答案:(11)static
(12)(int)(Math.random()*7)
(13)getXh()
6. 下面的程序定义了一个线程TimeThread,该线程每隔1秒钟输出显示一次当前系统时间,在main方法中使用TimeThread类创建3个新线程,并启动这些线程,请将下面的程序填写完整。 import java.util.*;
class TimeThread implements (14) { public void run() { while (true) {
Date currentTime = new Date(); try {
(15) ; // 休眠1秒钟 }
catch (Exception e) {System.out.println(e.toString());}
System.out.println(Thread.currentThread().getName()+\
} } }
public class Ex2 {
public static void main(String[] args){ }
答案:(14)Runnable (15)Thread.sleep(1000) String[] names={\ TimeThread myThread = new TimeThread(); for(int i=0;i<3;i++){
Thread threadObj= new Thread(myThread,names[i]); (16) ; //启动线程 } }
String[] xhs = {\int index = (12) ; //生成0~6之间的随机数。 return xhs[index];
System.out.println(\随机抽取的学号为:\ (13) );
public static void main(String[] args){
(16)threadObj.start()
7.下面的程序对“百鸡百钱”问题进行了求解,公鸡每只3元,母鸡每只5元,小鸡3只1元,用100元钱买100只鸡,公鸡、母鸡、小鸡应各买多少?请将程序填写完整。 public class Ex3 { } }
答案:(17)a<=33 (18)b<=20
(19)c%3==0
8. 下面的程序使用BufferedWriter类在D:\\Hello.txt文件中写入10万个数并输出所用的时间,请将程序填写完整。
import java.io.*; public class Ex4 {
public static void main(String[] args) throws IOException{ } }
答案:(20)new FileWriter(“D:\\\\Hello.txt”) (21)fw.write
9.根据程序注释提示将下面的程序填写完整。
class StringExample
{ public static void main(String args[]) { String s1=new String(\ String s2=new String(\
int x = (22) ; // 将s1转换为int类型 double y = (23) ; // 将s2转换为double类型
long t = System.currentTimeMillis(); for (int i=1;i<=100000;i++){ } fw.close();
t=System.currentTimeMillis()-t;
System.out.println(\
(21) ( i +\
BufferedWriter fw =new BufferedWriter( (20) ); public static void main(String[] args){
int a,b,c;
for ( a=0; (17) ; a++ ){
for ( b=0; (18) ; b++ ) {
c=100-a-b;
if ( (3*a+5*b+c/3==100) && ( (19) ) )
System.out.println(\公鸡:\ 母鸡:\ 小鸡:\ } }
double z = x + y;
String s3 = (24) ; //将z转换为字符串 StringBuffer sbr = new StringBuffer(\ String s4 = new String(\
(25) ; //将s4连接在sbr的后面
System.out.println(sbr.toString()); //显示为 Thingking in Java
} }
相关推荐:
- [综合文档]应答器设备技术规范(征求意见稿)A1
- [综合文档]教师 2012年高考政治试题按考点分类汇
- [综合文档]保险公司的总经理助理竞职演说
- [综合文档]卫生应急大练兵大比武活动考试--题库(
- [综合文档]徐州经济技术开发区总体规划环境影响报
- [综合文档]汉语拼音表(带声调)
- [综合文档]二年级 上 思维训练( 1~18)
- [综合文档]特色学校五年发展规划
- [综合文档]机床经常出现报警“X1轴定位监控”
- [综合文档]《电子技术基础》21.§5—2、3、4 习题
- [综合文档]浙江省深化普通高中课程改革
- [综合文档]CRISP原理 - 图文
- [综合文档]2017年电大社会调查研究与方法形考答案
- [综合文档]浅析建筑施工安全毕业论文
- [综合文档]《回忆我的母亲》名师教案
- [综合文档]装饰装修工程监理规划
- [综合文档]三下乡心得体会-文艺
- [综合文档]柱计算长度系数 - 图文
- [综合文档]全流程思考,提高燃电系统热电转换率--
- [综合文档]2018年嘉定区中考物理一模含答案
- 433M车库门滚动码遥控器
- 8、架空线路施工规范
- 大学四年声乐学习的体会
- 新北师大版五年级数学上册《轴对称再认
- 部编版五年级上册语文第六单元小结复习
- 小学六年级英语形容词用法
- 第2课 抗美援朝保家卫国 课件01(岳麓版
- 2015年天津大学运筹学基础考研真题,考
- 微机计算机控制技术课后于海生(第2版)
- 安全教育实践活动
- Delphi程序设计教程_第1章_Delphi概述
- 第八讲 工业革命与启蒙运动
- 《中华人民共和国药典》2005年版二部勘
- 科粤版九年级化学2.3构成物质的微粒(1)
- 西师大版数学三年级下册《长方形、正方
- ch6_冒泡排序演示
- 第4章 冲裁模具设计
- 浙江中小民营企业员工流失论文[终稿]
- 再议有线数字电视市场营运模式
- 昆明供水工程监理大纲




