云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > JAVA复习题

JAVA复习题

  • 62 次阅读
  • 3 次下载
  • 2026/1/10 11:17:29

30、创建一个长宽均为120的Frame窗口,且窗口的背景颜色是绿色。选择正确的语句添入下列横线处。 import java.awt.*;

public class Test extends Frame{

public static void main(String[] args){ Test a=new Test(); a.setSize(120,120);

a.setBackground(Color.green); a.setVisible(true); } }

31、打印右图图形。 public class p1{ ***** public static void main(String[] args){ **** int i,j; *** for(i=4;i>=0;i--) ** for(j=0;j<=i;j++){ * system.out.print(“*”) }

}System.out.println(“”); }

32、字符串处理的两个类是: StringBuffer String

33、捕获异常和 抛出异常 是异常处理的两个过程。

34、当方法有返回值时,必须在方法体内使用 return 语句。 35、组件是构成 图形用户化界面 的最小元素。

36、Applet生命周期是:从创建到消亡的周期 init() start() stop() destroy 37. 一个Java Application源程序文件名为MyJavaApplication.java,如果使用Sun公司的Java开发工具JDK编译该源程序文件并使用其虚拟机运算这个程序的字节码文件,应该顺序执行如下两个命令:

Javac MyJavaApplication.java 、 Java MyJavaApplication 。

38.class A { private int x; private int y;

A(int x,int y) {

this.x=x ; //参数x赋给类A属性x this.y=y ; //参数y赋给类A属性y }

} class B extends A{ private int k;

B(int x,int y) {

this(x,y35) ; //调用B类本身的含有三个参数的构造器并且参数分别为x,y,35

} B(int x,int y,int ktemp) {

super(x,y) ; //调用父类A的构造器 k=ktemp;

}

} }

39. 定义一个长度为5的字符串数组,并初始化其初值为“open”, “door”, “the”,

“open”, “name”;计算该数组中 “open”出现的次数,并倒序输出数组元素。 public class Test{

public void static main(String[] args){ //声明并初始化数组

String[]a={“open”, “door”,”the”,”open”,”name”}; int count = 0;

//计算该数组中 “open”出现的次数 for(int I=0;I<5;I++) {

if(a[i]equals “open”

count++;

}

//倒序输出数组元素

for(int I=0;I<5;I++) {

System .out.print(a[4-i]); }}}

40.创建类的对象时,使用运算符_new_给对象分配内存空间。 41.定义类的构造方法不能有返回值类型,其名称与_类_名相同。 三、写出下列程序完成的功能(8题)-考试(2题,共8分) 1、

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( \ }

}

计算1+1/2+…+1/100求和,sum=5.187377517639621 2、 import java.io.* ; public class Reverse

{ public static void main(String args[ ]) { int i , n =10 ;

int a[ ] = new int[10]; for ( i = 0 ; i < n ; i ++ ) try {

BufferedReader br = new BufferedReader( new InputStreamReader(System.in));

a[i] = Integer.parseInt(br.readLine( )); // 输入一个整数 } catch ( IOException e ) { } ; for ( i = n-1 ; i >= 0 ; i ―― ) System.out.print(a[i]+\ System.out.println( );

} } 输入10个整数 按逆序输出 3、 import java.awt.*;

import javax.swing.*; public class abc

{ public static void main(String args[]) { new FrameOut(); } }

class FrameOut extends JFrame // JFrame为系统定义的窗框类 { JButton btn; FrameOut( )

{ super(\按钮\

btn = new JButton(\按下我\ setLayout(new FlowLayout( )); add(btn);

setSize(300,200); setVisible(true); }

}

创建一个窗体,窗体有个组件组建

的名字是按下我

4、import java.io.*;

public class abc

{ public static void main(String args[]) { SubClass sb = new SubClass( ); System.out.println(sb.max( )); } }

class SuperClass { int a = 10 , b = 20 ; }

class SubClass extends SuperClass

{ int max( ) { return ((a>b)?a:b); } } 返回最大值 结果为20

5、public class ArrayCopy{

public static void main(String[] args){ int []a={91,92,93,94}; int []b=new int[6];

System.arraycopy(a,0,b,0,a.length); b[4]=95; b[5]=96; a=b;

for(int i=0;i

}改变数组a的值并把数组a复制到数组b上

搜索更多关于: JAVA复习题 的文档
  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

30、创建一个长宽均为120的Frame窗口,且窗口的背景颜色是绿色。选择正确的语句添入下列横线处。 import java.awt.*; public class Test extends Frame{ public static void main(String[] args){ Test a=new Test(); a.setSize(120,120); a.setBackground(Color.green); a.setVisible(true); } } 31、打印右图图形。 public class p1{ ***** public static void main(String[] args){ **** int i,j;

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com