2014年4月自考Java语言程序设计(一)试题及答案资料 下载本文

深圳自考报名网:http://www.0755zikaobaoming.com

URL url= new URL(urlName);//由网址创建 URL 对象 URLConnection tc =url.openConnection();//获得 URLConnection 对象 tc.connect( );//设置网络连接 InputStreamReader in = new InputStreamReader(tc.getInputStream( )); BufferedReader

dis

=

new

BufferedReader(in);

String

inLine;

while((inLine=dis.readLine(

))!=null)

{ showArea.append(inLine+\} dis.close(); } catch (MalformedURLException e2) {e2.printStackTrace();} catch(IOException e3) { e3.printStackTrace();} } }

六、程序设计题(本大题共2小题,每小题6分,共1 2分)

37.编写方法int[] arrayReverse(int[]a),该方法的功能是返回一个新的数组b,新数组的 元素排列顺序与参数数组的元素排列顺序相反。 答:

int[] arrayReverse(int[] a) {

int[] b = new int[a.length]; for (int i=0;i

b[a.length-1-i] = a[i] ; } return b;

}

38.类InputData是用于输入考生考号、课程和成绩的窗口, 窗口的界面如右图所示,其中三个文本框用来输入考号、课 程和成绩。

注:这里是给定程序的部分代码,你要编写的是完成该类的构 造方法。

import java.awt.*;import javax.swing.*; import java.awt.event.*;

public class InputData extends JFrame implements ActionListener{

JTextField noText, markText, courseText; JButton ok=new JButton(\确 定\);

public static int no, mark;∥让创建者直接获取考号和成绩 public static String course;∥让创建者直接获取课程名称 InputData(){

super(\成绩输入窗\); Container con = getContentPane(); con.setLayout(new GridLayout(4, 1)); noText = new JTextField(12); courseText = new JTextField(12);

═══════════════════════════════════════════════════════════════════════════════

深圳自考报名网:http://www.0755zikaobaoming.com

markText = new JTextField(12); ∥请在答题纸相应位置编写代码

con.add(ok); ok.addActionListener(this); con.setSize(250, 70); setVisible(true); pack(); }

public void actionPerformed(ActionEvent e) {

if (e.getSource() = ok) { ∥读取考号和成绩

no = Integer.parseInt(noText.getText()); course = courseText.getText();

mark = Integer.parseInt(markText.getText()); setVisible(false); dispose(); } }

public static void main(String[] args) {

new InputData(); } }

以下一段为答案:---------------------------------------------------------------- JPanel p1 = new JPanel( );

p1.add(new JLabel(\考 号\ p1.add(noText); con.add(p1);

JPanel p2 = new JPanel( );

p2.add(new JLabel(\课 程\ p2.add(courseText); con.add(p2);

═══════════════════════════════════════════════════════════════════════════════

深圳自考报名网:http://www.0755zikaobaoming.com JPanel p3 = new JPanel( );

p3.add(new JLabel(\成 绩\ p3.add(markText); con.add(p3);

//以上一段为答案----------------------------------------------------------------- con.add(ok);ok.addActionListener(this);

con.setSize(250,

70);setVisible(true);pack();

}

public

void

actionPerformed(ActionEvent e) { if (e.getSource()==ok) { //读取考号和成绩 no = Integer.parseInt(noText.getText()); course = courseText.getText(); mark = Integer.parseInt(markText.getText()); setVisible(false); dispose(); } } public static void main(String[] args) { new InputData(); } }

═══════════════════════════════════════════════════════════════════════════════

深圳自考报名网:http://www.0755zikaobaoming.com

public static String course;//让创建者直接获取课程名称 InputData() { super(\成绩输入窗\Container con = getContentPane(); con.setLayout(new GridLayout(4, 1)); noText = new JTextField(12); courseText = new JTextField(12); markText = new JTextField(12); //请在答题纸相应位置编写代码: //以下一段为答案:----------------------------------------------------------------JPanel p1 = new JPanel( ); p1.add(new JLabel(\考 号\p1.add(noText); con.add(p1); JPanel p2 = new JPanel( ); p2.add(new JLabel(\课 程\p2.add(courseText); con.add(p2); JPanel p3 = new JPanel( ); p3.add(new JLabel(\成 绩\

p3.add(markText);

con.add(p3);

//

-----------------------------------------------------------------con.add(ok);ok.addActionListener(this); con.setSize(250,

70);setVisible(true);pack(); } public void actionPerformed(ActionEvent e) { if (e.getSource()==ok) { //读取考号和成绩 no = Integer.parseInt(noText.getText()); course = courseText.getText(); mark = Integer.parseInt(markText.getText()); setVisible(false); dispose(); } } public static void main(String[] args) { new InputData(); } }

═══════════════════════════════════════════════════════════════════════════════