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上
相关推荐: