二级java考试真题(1)(2)

2019-03-27 23:00

import java.awt.event.*;

public class Java_2 extends Frame { public Java_2(String s){ super(s); } public static void main(String args[]){ Java_2 fr = new Java_2(\ Button b=new Button(\ //*********Found********

b.addActionListener(_new HandleButton()_____); fr.add(b); fr.pack();

//*********Found********

fr.addWindowListener(new _WindowAdapter_____(){ public void windowClosing(WindowEvent e) { System.exit(0); } }); fr.setVisible(true); } }

class HandleButton implements ActionListener{ public void actionPerformed(ActionEvent e){ System.out.println(\ } }

3. //*********Found******** import javax.swing______.*;

public class Java_3 {

public static void main( String args[] ) {

String s1, s2, s3, s4, output;//声明5个字符串引用 //初始化字符串

s1 = new String( \您好!\ s2 = new String( \您好!\ // 判别字符串相同否 if (s1 == s2 )

output =

\和 s2 是内存中同一个对象\ else

output =

\和 s2 不是内存中同一个对象\ //判别字符串内容相等否 //*********Found******** if (s1.equals(s2)______ )

output += \和 s2内容相等\ else

output += \和s2 内容不相等are not equal\

// 用intern()方法来获得与对象s1,s2内容都是\您好!\字符串的引用s3 和 s4 //*********Found******** s3 = s1__.intern()____; //*********Found******** s4 = s2__.intern()_____;

//判别s3和s4是否是内存中相同的对象 if ( s3 == s4 ) output +=

\和s4 是内存中同一个对象\ else

output +=

\和 s4 不是内存中同一个对象\

//判别s1和s3是否引用同一个对象 if ( s1 == s3 ) output +=

\和s3是内存中同一个对象\ else

output +=

\和s3不是内存中同一个对象\

// 判别s2和s4是否是内存中相同的对象 if ( s2 == s4 ) output +=

\和s4是内存中同一个对象\ else

output +=

\和s4不是内存中同一个对象\ //判别s1和s4是否是内存中同一个对象 if ( s1 == s4 )

output +=

\和s4是内存中同一个对象\ else

output +=

\和s4不是内存中同一个对象\

JOptionPane.showMessageDialog( null, output, //*********Found******** \示范

String的intern()方法_____\

JOptionPane.INFORMATION_MESSAGE );

System.exit( 0 ); } }

第四套:

1.import javax.swing.JApplet; // import class JApplet import java.awt.Graphics; // import class Graphics

public class Java_1 extends JApplet {

//*********Found********

public void paint( _Graphics_____ g ) {

g.drawString( \欢迎你参加Java考试!\ } }

2. import java.io.*; public class Java_2 {

public static void main(String[] args) throws IOException {

File inputFile; File outputFile; FileInputStream in; FileOutputStream out; int c;

inputFile = new File(\ outputFile = new File(\ in = new FileInputStream(inputFile); //*********Found********

__out = new FileOutputStream____(outputFile);

while ((c = in.read()) != -1) //*********Found******** _ out.write(c)_____;

in.close(); out.close(); } }

3. import javax.swing.JOptionPane;

public class Java_3 {

public static void main( String args[] ) {

String firstNumber, // 用户输入第1个字符串 secondNumber, // 用户输入第2个字符串 result; // a string containing the output int number1, // 比较的第1个数 number2; // 比较的第2个数

//读用户输入的第1个字符串 read first number from user as a string firstNumber =

JOptionPane.showInputDialog( \

//读用户输入的第2个字符串read second number from user as a string secondNumber =

JOptionPane.showInputDialog( \

// 将字符串类型转换成整数类型

number1 = Integer.parseInt( firstNumber ); number2 = Integer.parseInt( secondNumber ); result = \

//*********Found******** if ( number1 = number2 )

result = number1 + \

if ( number1 != number2 )

result = number1 + \

if ( number1 < number2 )

result = result + \

if ( number1 > number2 )

result = result + \

if ( number1 <= number2 )

result = result + \

//*********Found******** if (; number1 >= number2 )

result = result + \

//显示结果

//*********Found********

_JOptionPane.showMessageDialog_____( null, result, \比较结果 \ //*********Found********

_JOptionPane._____INFORMATION_MESSAGE );

//程序正常退出

//*********Found******** __ System.exit(0)____; } }

第五套:

1. import javax.swing.JApplet; import java.awt.Graphics;

//*********Found********

public class Java_1 extends __JApplet____ { public void paint( Graphics g ) {

g.drawString( \欢迎你来参加\ g.drawString( \语言考试!\ } }

2. import java.awt.* ; import java.applet.* ;

public class Java_2 extends Applet {


二级java考试真题(1)(2).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:低压配电柜的特点、安装及调试 - secret

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: