java简单的java程序设计填空题填空

java一些很简单的填空题
本回答由提问者推荐
var sogou_ad_id=731547;
var sogou_ad_height=160;
var sogou_ad_width=690;您的访问出错了(404错误)
很抱歉,您要访问的页面不存在。
1、请检查您输入的地址是否正确。
进行查找。
3、感谢您使用本站,3秒后自动跳转至网站首页Java程序填空_百度文库
您的浏览器Javascript被禁用,需开启后体验完整功能,
赠送免券下载特权
10W篇文档免费专享
部分付费文档8折起
每天抽奖多种福利
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
Java程序填空
阅读已结束,下载本文需要
想免费下载本文?
定制HR最喜欢的简历
下载文档到电脑,同时保存到云知识,更方便管理
加入VIP
还剩31页未读,
定制HR最喜欢的简历
你可能喜欢当前位置: >>
Java复习题阅读程序题
《JAVA 程序设计》复习题之(三)阅读程序题 (通信工程专业使用)三、阅读程序题。 1、阅读以下程序: public class Sum { public static void main( String args[]) { double sum = 0.0 ; for ( int i = 1; i&= 100; i ++ ) sum +=, System.out.println( &sum=& + sum ); } } 该程序完成的功能是: 求 sum=1+2+3+...+100 的和。 2、阅读以下程序: public class Sum { public static void main(String args[]) { double sum = 0.0: for (int i=1; i&=100; i++) sum += i*i; System.out.println( &sum=&+sum); } } 该程序的功能是: 求出 sum 的值为 1 到 100 的平方和。 3、阅读以下程序: public class Sum { public static void main(String args[]) { double sum = 0.0; for(int i = 1; i &= 100; i++) sum += i*i*i; System.out.println(&sum=& + sum); } } 此程序完成的功能是: 计算并输出 1 到 100 的立方和 sum 值。 4、阅读以下程序: public class Sum { public static void main(String args[]) { double sum = 0.0; for (int i=1; i&=100; i++) sum += 1.0 / (double)i; System.out.println(&sum=&+sum); } } 此程序完成的功能是: 求解 sum=1+1/2+1/3+...+1/100 的值并打印输出。 5、阅读以下程序 import java.io.* ; public class Test { public static void main(String args[ ]) { int i, s = 0; int a[] = {10, 20, 30, 40, 50, 60, 70, 80, 90}; for ( i = 0 ; i & a. i++ ) if(a[i] % 3 == 0) s += a[i]; System.out.println(&s=& + s); } } 请写出此程序的输出结果: s=1806、阅读以下程序 import java.io.*; public class abc { public static void main(String args [ ]) { AB s = new AB(&Great!&,&I love Eclipse.&); System.out.println(s.toString( )); } } class AB { String s1; String s2; public AB(String str1, String str2) { s1 = str1; s2 = str2; } public String toString( ) { return s1 + s2; } } 运行结果是: 运行结果是:Great! I love Eclipse. 7、阅读以下程序 import java.io.* ; public class abc { public static void main(String args[ ]) { int i, s = 0 ; int a[ ] = { 10 , 20 , 30 , 40 , 50 , 60 , 70 , 80 , 90 }; for ( i = 0 ; i & a. i ++ ) if ( a[i]%3 = = 0 ) s += a[i] ; System.out.println(&s=&+s); } } 运行结果是: 运行结果:s = 180 8、阅读以下程序 import java.io.* ; public class abc { public static void main(String args[ ]) { System.out.println(&a=& + a + &\nb=& + b); } } class SubClass extends SuperClass { SubClass(int aa, int bb, int cc) { super(aa, bb); c = } } class SubSubClass extends SubClass { SubSubClass(int aa, int bb, int cc) { super(aa, bb, cc); A = aa + bb + } void show( ){ System.out.println(&a=&+a+&\nb=&+b+&\nc=&+c); } } 运行结果是: 运行结果: a=60 b=20 c=30 9、以下程序的输出结果为 class StringTest1 { public static void main(String[] args) { String s1=&hello&; String s2=new String(&hello&); if( s1.equals(s2) ) System.out.println(&相等&); else System.out.println(&不相等&); } } 相等 。10、以下程序段的输出结果为 public class TestArray {5 6 7 8 9。public static void main(String args[ ]) { int i , int a[ ] = { 5,9,6,8,7}; for ( i = 0 ; i & a.length-1; i ++ ) { int k = for ( j = j & a. j++ ) if ( a[j] & a[k] ) k = int temp = a[i]; a[i] = a[k]; a[k] = } for ( i =0 ; i&a. i++ ) System.out.print(a[i]+& &); System.out.println( ); } }11、写出以下程序的功能。 import java.io.*; public class TestFile { public static void main(String args[]) throws Exception { BufferedReader br = new BufferedReader( new InputStreamReader(System.in)); BufferedWriter bw = new BufferedWriter(new FileWriter(“input.txt&)); S while (true) { System.out.print(&请输入一个字符串: &); System.out.flush( ); s = br.readLine( ); if (s.length() == 0) bw.write(s); bw.newLine(); } bw.close( ); } } 程序功能是: 程序功能是:从键盘逐一输入字符串,逐一输出至 input.txt 文件中,直至输入空行。 12、阅读以下程序,写出输出结果。 class Animal { Animal( ) { System.out.print (&Animal } public class Dog extends Animal { Dog( ) { System.out.print (&Dog &); } public static void main(String[ ] args) { Dog snoppy = new Dog(); } } 输出结果是: 输出结果是:Animal Dog Peter is 17 years old! 。 &); }13、以下程序的输出结果为 public class Person { Spublic Person(String name, int age) { this.name = this.age = }public static void main(String[] args) { Person c = new Person(&Peter&, 17); System.out.println(c.name + & is & + c.age + & years old!&); } }14、以下程序的输出结果为__ public class Course { private String cN private String cN private int cU课程号:101 课程名:JSP 学分:3___。public Course(String number, String name, int unit) { cNumber = cName = cUnit = }public void printCourseInfo() { System.out.println(&课程号:& + cNumber + &课程名:& + cName + & 学分:& + cUnit); } }class CourseTest { public static void main(String[] args) { C c = new Course(&101&, &JSP&, 3); c.printCourseInfo(); } }15、以下程序的输出结果为__ public class Tom {
private static S汤姆猫体重:20.0 斤___。public void setWeight(float weight) { this.weight = }private void out() { System.out.println(name + &体重:& + weight + &斤&); }public static void main(String[] args) { Tom.name = &汤姆猫&; Tom cat = new Tom(); cat.setWeight(20); cat.out(); } }16 、 以 下程 序 的 输出 结果 是 话: 学校:宿中_。 public class Father { String name, address,_姓 名 :Tom 年 龄 :15 家 庭 住 址 :宿 城 区 电public Father(String name, int age) { this.name = this.age = } void out() { System.out.print(&姓名:& + name); System.out.print(& 年龄:& + age); } void outOther() { System.out.print(& 家庭住址:& + address); System.out.print(& 电话:& + tel); } }class Son extends Father { S public Son(String name, int age) { super(name, age); } void out() { super.out(); super.outOther(); System.out.println(& 学校:& + school); }public static void main(String args[]) { Son son = new Son(&Tom&, 15); son.address = &宿城区&; son.school = &宿中&; son.tel = &&; son.out(); } } 17、下列程序的运行结果是__ public class MyClass { int a[] = { 1, 2, 3, 4, 5 }; 12345____。void out() { for (int j = 0; j & a. j++) System.out.print(a[j] + &&); }public static void main(String[] args) { MyClass my = new MyClass(); my.out(); } } 18、阅读下面的程序,回答问题。 import java.awt.*; import javax.swing.*; public class T extends JFrame { public T ( ) { super(&GridLayout&); Container con=this.getContentPane(); con.setLayout(new GridLayout(2,3)); con.add(new JButton(&a&)); con.add(new JButton(&b&)); con.add(new JButton(&c&)); con.add(new JButton(&d&)); con.add(new JButton(&e&)); con.add(new JButton(&f&)); setSize(200, 80); setVisible(true); } public static void main(String args[]) { new T(); } } ①画图表示程序运行后的图形界面。 ②如果程序通过实现某个接口处理按钮的动作事件, 则该接口名为何?接口中的方法头声明 如何? 答案:① ②接口名:ActionListener 接口中的方法:public void actionPerformed(ActionEvent e)19、阅读下面的程序,并回答问题。 import java.io.*; public class Test { public static void main(String args[]) throws IOException { BufferedReader buf=new BufferedReader( new InputStreamReader(System.in)); while (true) { String str = buf.readLine( ); if( str.equals(&quit&) ) int x = Integer.parseInt(str); System.out.println(x*x); } } } 编译运行上面的程序: ①从键盘输入 5,回车后输出的结果如何? ②从键盘输入 quit,回车后程序执行情况如何? 答案: ①25 ②终止应用程序的运行。20、阅读下面的程序代码,并回答问题。 String s1 = new String(&abcde&); String s2 = new String(&abcde&); boolean b1= s1.equals(s2); boolean b2 = s1== s2; System.out.print(b1+& &+b2);?程序段执行后,在命令行的输出结果如何? ?解释输出(1)的结果的原因? 答案: ? true false ?equals 方法比较两个字符串的内容是否相等;运算符“==”判断两个对象是否指向同一个 引用,即是否为同一个对象。21、阅读下面的程序,并回答问题。 import java.io.*; public class Test { public static void main(String args[]) throws IOException { BufferedReader buf=new BufferedReader( new InputStreamReader(System.in)); while (true) { String str = buf.readLine(); if( str.equals(&quit&) ) int x = Integer.parseInt(str); System.out.println(x*x); } } } 编译运行上面的程序: ?从键盘输入 10,回车后输出的结果如何? ?从键盘输入 exit,回车后程序能正确执行吗?为什么? 答案: ?100 ?不能;因为方法 Integer.parseInt(str)不能将字符串“exit”转化为整数,抛出异常。22、 、写出下面的程序编译、运行后的结果。 public class Test{ public static void main(String args[]) { new Student(&Tom&, 'm', 90, 88); new Student(&Jack&, 'm', 66, 89); new Student(&Mary&, 'f', 76, 86); System.out.println(&name\tsex\tchinese\tenglish&); Student.print(); } }class Student { protected protected protected protected protected StriSstatic SStudent (String name, char sex, int chinese, int english) this.name= this.sex= this.chinese= this.english= this.next= list= } static void print() { Student friend={ if (friend==null) System.out.println(&The list is empty.&); else { do{ System.out.println(friend.toString()); friend=friend. }while(friend!=null); } } public String toString() { return new String(name+&\t&+sex+&\t&+chinese+&\t&+english); } } 答案: name Mary Jack Tom sex f m m chinese english 76 86 66 89 90 8823、阅读下列程序: public class Sum{ public static void main(String [] args){ int j=10; System.out.println(&j is : &+j); calculate(j); System.out.println(&At last, j is : &+j); } static void calculate (int j){ for (int i = 0;i&10;i++) j++; System.out.println(&j in calculate() is: &+j); } } 输出结果为: j is : (1) j in calculate() is : At last j is :(2) (3)答案:(1) 10; (2) 20; (3) 10。24、按要求填空 abstract class SuperAbstract{ void a(){…} abstract void b(); abstract int c(int i); } interface AsSuper { void x( ); } abstract class SubAbstract extends SuperAbstract implements AsSuper { public void b( ){…} abstract String f( ); } public class InheritAbstract extends SubAbstract{ public void x( ) {…} public int c(int i ) {…}public String f( ) {…} public static void main(String args[]){ InheritAbstract instance = new InheritAbstract( ); instance.x(); instance.a(); instance.b(); instance.c(100); System.out.println(instance.f()); } } 在以上这段程序中: 抽象类有:SuperAbstract 和 非抽象类有: 接口有: (1) (2) (3) (写出类名) (写出类名) (写出接口名) AsSuper 中的 x()方法是(4)方法,所以在 InheritAbstract 中必须对它进行(5) 答案: (1) SuperAbstract; (2) InheritAbstract; (3) AsSuper; (4) 抽象; (5) 覆盖和实现。25、按注释完成程序 public class Leaf { private int i = 0; //此属性值用于检验 Leaf increment( ){ //定义方法 increment(),返回值是 Leaf 类的对象 i++; return (1) ________ } void print( ) { System.out.println(& i = & + i); } public static void main(String args[ ]){ Leaf x = (2) ________ ; //创建 Leaf 类的对象 //将当前对象的地址作为返回值返回x.increment( ).increment( ).increment().print(); }//多次调用方法 increment( ),返回的都是 x 的地址,i 值表示调用次数 } 输出结果为 i = 答案: (1) this; (2) new Leaf(); (3) 3 (3) ________26、 按注释提示完成文件复制的程序 //FileStream 源代码如下: import java.io.*; class FileStream { public static void main(String args [ ]) { try { File inFile = new File(&file1.txt&); File outFile = new File(&file2.txt&); FileInputStream fis =(1)________ //指定源文件 //指定目标文件 ________;FileOutputStream fos = new FileOutputStream(outFile); //逐字节从源文件中输入,再输出到 fos 流 while ((c = fis.read ())!=-1) (2)________________________; fis.close(); fos.close(); } catch (Exception e) { System.out.println(&FileStreamsTest: &+e); } } } 答案: (1) new FileInputStream(inFile); (2) fos.write(c);27、阅读程序,写出结果: // AbstractClassDemo.java 源代码如下: abstract class Shape { abstract void display(); } class Circle extends Shape { void display() { //实现抽象类的方法 //定义抽象类 Shape 和抽象方法 displaySystem.out.println(&Circle&); } } class Rectangle extends Shape { void display() { //实现抽象类的方法System.out.println(&Rectangle&); } } class Triangle extends Shape { void display() { //实现抽象类的方法System.out.println(&Triangle&); } } public class AbstractClassDemo{ public static void main(String args[]){ (new Circle()).display(); //定义无名对象来调用对应的 display 方法 (new Rectangle()).display(); (new Triangle()).display(); } } 输出结果是? 答案:(1) Circle; (2) Rectangle; (3) Triangle。 28、阅读下列代码,说出这段程序的功能。 import java.io.*; public class Test{ public static void main( String [] argv) { try { BufferedReader is = new BufferedReader( new InputStreamReader(System.in)); String inputL While ((inputLine = is.readLine ())!= null) { System.out.println(inputLine); } is.close(); }catch (IOException e) { System.out.println(&IOException: & + e); } } } 程序的功能是:________________________________________________________ 答案:读取键盘输入,显示到屏幕上,直到键盘输入为空为止。29、阅读下列程序,写出正确的运行结果。 class test { public static void main (String [ ] args ){ int x = 9, if ( x &= 0) if (x & 0) y = 1; else y = 0; else y = -1; System.out.println(y); } } 程序的输出结果是:________________ 答案:130、 阅读程序,写出正确的运行结果。 public class Father{ int a = 100; public void miner( ) { a--; } public static void main(String[] args){ Father x = new Father(); Son y = new Son(); System.out.println(y.a); System.out.println( y.getA()); y.miner(); System.out.println(y.a); System.out.println(y.getA()); } } class Son extends Father{ int a = 0; public void plus( ) { a++; } public int getA( ) { return super.a; } } 程序的输出结果是? 答案: 0 100 0 99 31、阅读以下程序: import java.io.*; publiic class Test { public static void main(String args[]) { AB s = new AB(&Hello!&,&I love Java.&); System.out.println( s.toString() ); } } class AB { S String s2; AB( String strl, String str2 ) { sl = str1; } public String toString() { return sl + s2; } } 该程序的输出结果是:________________________________________ Hello!I love Java. s2 = str2;
更多搜索:
All rights reserved Powered by
文档资料库内容来自网络,如有侵犯请联系客服。最简单的Java框架
框架framework的目的是定义骨架式方案,处理各种同样的底层细节;而开发者使用框架时,可以按照自己的需求实现自己的功能——只需要填入自己的东西/flesh。
最简单的框架,类似于JUnit,它有一个main(String[] args)启动本框架。如果是applet或GUI框架,就有太多底层细节需要处理。
package principle.callback.
* 最简单的框架
* @author yqj2065
* @version 2014.10
public interface MyFramework{
public double op(double m,double n);
}最简单的框架就是一个函数接口lower.MyFramework,它对两个double操作后返回一个double值。
package principle.callback.
import tool.G
public class Main{
* 命令行启动本框架。
* @param args 至少两个double
public static void main(String[] args){
MyFramework f = (MyFramework)God.create("2065");
double d =f.op(Double.parseDouble(args[0]),Double.parseDouble(args[1]));
System.out.println(d);
* 和JUnit一样,提供App调用的方式。
public static double runFramework(MyFramework f,double x,double y){
return f.op(x,y);
注意,框架一般使用的技术就是反射和回调。
tool.God利用反射和配置文件创建某个对象,Main调用f.op(double,double),具体的方法体由上层代码提供。
ok,框架已经设计完成。
现在是我们应用程序员干活的时候了。
应用程序员最开始当然写HelloWorld,来熟悉框架...HelloWorld不能够和高傲的框架在一个包中。
package principle.
public class HelloWorld implements principle.callback.lower.MyFramework{
public double op(double m,double n){
return m+n;
}应用程序员还要按照框架的要求,自己写好配置文件。如果框架的文档说明:需要在my.properties中定义要创建的对象,于是我们在my.properties中加上:
2065=principle.callback.HelloWorld
接下来在命令行中运行框架,例如:
E:\designPattern>java principle.callback.lower.Main 1.2 3.4
有时候,我们应用程序员在应用程序中启动或调用框架,也可以:
package principle.
import tool.G
import principle.callback.lower.MyF
import principle.callback.lower.M
public class App{
public static void main(String[] args){
MyFramework f = (MyFramework)God.create("2065");
double d = Main.runFramework(f,1.2,3.4);
System.out.println(d);
}当然,设计App的程序员和设计HelloWorld的程序员同病相怜,自己人就不用反射了:
public static void test(){
double d = Main.runFramework(new HelloWorld(),1,3);
System.out.println(d);
MyFramework f = (double m,double n)->{return m *};
d = Main.runFramework(f,1,3);
System.out.println(d);
f = (m,n)->{return m +2*};
d = Main.runFramework(f,1,3);
System.out.println(d);
回调使得编写上层模块的程序员有了新的体验——填空式。
这就有了库与框架的区别——上层模块的程序员直接调用的,属于库函数;要求上层模块的程序员提供的回调函数的,属于框架。
如果我们通吃上层和下层,设计框架时使用回调机制;如果我们让愚蠢的应用程序员填空,哈哈,我们告诉他们一个术语——控制反转。
如果我们是框架的应用程序员,...好吧,我们也设计一个框架,控制反转。

我要回帖

更多关于 java程序填空题 的文章

 

随机推荐