77范文网 - 专业文章范例文档资料分享平台

2013-2014-1-java考试复习题库(5)

来源:网络收集 时间:2020-03-26 下载这篇文档 手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:或QQ: 处理(尽可能给您提供完整文档),感谢您的支持与谅解。点击这里给我发消息

in.close();

System.out.println(bufferOne); //【结果1】 System.out.println(bufferTwo); //【结果2】 }

catch(IOException e){} } }

6.请说出E类中System.out.println的输出结果。

6.答: public class E {

【结果1】: public static void main(String args[]){

【结果2】: long[] a={1,2,3,4};

long[] b={100,200,300,400,500};

b=a; System.out.println(\数组b的长度:\ //【结果1】 System.out.println(\ //【结果2】 } }

7.请说出E类中System.out.println的输出结果。

7.答: public class E {

【结果1】: public static void main(String args[]){

【结果2】: int[] a={10,20,30,40},b[]={{1,2},{4,5,6,7}};

b[0]=a;

b[0][1]=b[1][3]; System.out.println(b[0][3]); //【结果1】 System.out.println(a[1]); //【结果2】 } } 8.答: 8.请说出E类中System.out.println的输出结果。 【结果1】: class Fish{ 【结果2】: int weight=1; 【结果3】 } class Lake{ Fish fish; void setFish(Fish s){ fish=s; } void foodFish(int m){ fish.weight=fish.weight+m; } }

public class E{ public static void main(String args[]){ Fish redFish=new Fish(); System.out.println(redFish.weight); //【结果1】

21

Lake lake=new Lake(); lake.setFish(redFish); lake.foodFish(120); System.out.println(redFish.weight) ; //【结果2】 System.out.println(lake.fish.weight); //【结果3】 } }

9.请说出B类中System.out.println的输出结果。

class A{ public int getNumber(int a){

9. return a+1; 答: 【结果1】: }

【结果2】: }

class B extends A{

public int getNumber(int a){ return a+100; } public static void main(String args[]){ A a=new A(); System.out.println(a.getNumber(10)); //【结果1】 a=new B(); System.out.println(a.getNumber(10)); //【结果2】 } 10.答: } 【结果1】: 10.请说出E类中System.out.println的输出结果。 【结果2】: interface A{ double f(double x,double y); }

class B implements A{ public double f(double x,double y){ return x*y; } int g(int a,int b ){ return a+b; } }

public class E{ public static void main(String args[]){ A a=new B(); System.out.println(a.f(3, 5)); //【结果1】 B b=(B)a; System.out.println(b.g(3,5)); //【结果2】 } }

22

11.请说出E类中System.out.println的输出结果。

interface Com{ int add(int a,int b); }

abstract class A{ abstract int add(int a,int b);

}

class B extends A implements Com{

public int add(int a,int b){ return a+b; } }

public class E{ public static void main(String args[]){ B b=new B(); Com com=b; System.out.println(com.add(12,6)); //【结果1】 A a=b; System.out.println(a.add(10,5)); //【结果2】 } }

12.请说出E类中System.out.println的输出结果。 public class E{ public static void main(String args[]){ String str=new String(\苹果\ modify(str); System.out.println(str); //【结果1】 } public static void modify(String s){ s=s+\好吃\ System.out.println(s); //【结果2】 } }

13.请说出E类中System.out.println的输出结果。

public class E{

public static void main(String args[]){

byte d[]=\我们喜欢篮球\ System.out.println(d.length); //【结果1】

String s=new String(d,0,7); System.out.println(s); //【结果2】 } }

14.请说出E类中System.out.println的输出结果。

class MyString{

11 .答: 【结果1】: 【结果2】: 12.答: 【结果1】: 【结果2】: 13.答: 【结果1】: 【结果2】: 23

public String getString(String s){ StringBuffer str=new StringBuffer(); for(int i=0;i

public class E{ public static void main(String args[]){ String s=\ System.out.println(s); //【结果1】 MyString ms=new MyString(); System.out.println(ms.getString(s));//【结果2】 } }

六、模板编程题(请按模板要求,在指定位置写出【代码】答案,否则无效。)

1.

【代码1】: 【代码2】: 【代码3】: 【代码4】: 【代码5】:

import java.awt.*;

import java.awt.event.*;

class IenFrame extends Frame implements ActionListener { TextField text; Label label; IenFrame() {

【代码1】 //创建TextField对象:text,要求text的可见字符数为12个机器字符。

【代码2】 //创建 Label对象:label,要求label上的名字是\love this game\。

【代码3】 //设置窗口的布局为FlowLayout型布局。

【代码4】 //将当前窗口作为text的ActionEvent事件的监视器。 add(label); add(text); }

public void actionPerformed(ActionEvent e) {

【代码5】 //label调用方法将自己名字设置为text中的文本 } } 2.

24

【代码1】: 【代码2】: 【代码3】: 【代码4】: 【代码5】:

class IenString

{ public static void main(String args[]) { int index=-1,length=0,n=0; String str=\我非常喜欢1236\

index=【代码1】 //str调用方法返回\在str出现的位置 length=【代码2】 //str调用方法返回str中字符的个数

char c=【代码3】 //str调用方法返回str中的字符:'喜' String temp=【代码4】 //str调用方法返回字符串\ n=【代码5】 //将temp转化为int型数据。 System.out.println(n); } }

3.以下Java应用程序实现猜数字游戏,请将【代码】替换为Java语句。 import javax.swing.JOptionPane; public class GuessNumber {

public static void main (String args[ ]) {

System.out.println(\给你一个1至100之间的整数,请猜测这个数\ int realNumber=(int)(Math.random()*100)+1; int yourGuess=0;

String str=JOptionPane.showInputDialog(\输入您的猜测:\ yourGuess=Integer.parseInt(str); while(【代码1】) //循环条件 {

if(【代码2】) //条件代码 {

str=JOptionPane.showInputDialog(\猜大了,再输入你的猜测:\ yourGuess=Integer.parseInt(str); }

else if(【代码3】) //条件代码 {

str=JOptionPane.showInputDialog(\猜小了,再输入你的猜测:\ yourGuess=Integer.parseInt(str); } }

System.out.println(\猜对了!\ } }

4.以下是Java实现的回文数程序,请将【代码】替换为Java语句。

25

百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说教育文库2013-2014-1-java考试复习题库(5)在线全文阅读。

2013-2014-1-java考试复习题库(5).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印 下载失败或者文档不完整,请联系客服人员解决!
本文链接:https://www.77cn.com.cn/wenku/jiaoyu/875391.html(转载请注明文章来源)
Copyright © 2008-2022 免费范文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ: 邮箱:tiandhx2@hotmail.com
苏ICP备16052595号-18
× 注册会员免费下载(下载后可以自由复制和排版)
注册会员下载
全站内容免费自由复制
注册会员下载
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: