教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 文库大全 > 专业资料 >

04747Java语言程序设计(一)历年真题2(2)

来源:网络收集 时间:2026-08-29
导读: System.out.println(\t刚开始的值是:+mrc.getVal()); System.out.println(\t多个线程正在工作,请稍等!); for(int i = 0; i 20; i++) { int d = i % 2 == 0 ? 50 : -30; aThreadArray[i] = new Thread(new MyMultiTh

System.out.println("\t刚开始的值是:"+mrc.getVal()); System.out.println("\t多个线程正在工作,请稍等!"); for(int i = 0; i < 20; i++) {

int d = i % 2 == 0 ? 50 : -30;

aThreadArray[i] = new Thread(new MyMultiThreadClass(mrc, d)); aThreadArray[i].start(); }

WhileLoop ://等待所有线程结束 while(true){

for(int i = 0; i < 20; i++)

if(aThreadArray[i]. _________ ())continue WhileLoop; break;

}

System.out.println("\t最后的结果是: "+mrc.getVal());

} }

class MyMultiThreadClass implements Runnable { ShareData UseInteger; int delta;

MyMultiThreadClass(ShareData mrc, int d) {

UseInteger = mrc; delta = d; }

public void run() {

for(int i = 0; i < 1000; i++) { UseInteger.modiData(delta);

try {Thread.sleep(10) ;//做一些其他的处理 }catch(InterruptedException e){ }

} } }

class ShareData { int val;

ShareData(int initValue){val = initValue; } int getVal(){return val;}

private void putVal(int v){val = v;} _________ void modiData(int d){ putVal(getVal() + d);

} }

五、程序分析题(本大题共5小题,每小题4分,共20分) 32.阅读下列程序,请写出该程序的输出结果。

class A { int x, y;

A(int a, int b) {

x= a; y= b; } }

public class sample {

public static void main(String args[]) { A pl, p2;

p2 = new A(12, 15); p1 = p2; p2.x++;

System.out.println("p1.x=" + p1 .x); } }

33.阅读下列程序,请写出调用pascal(4)的输出结果。

static void pascal(int n) { int pas[];

pas = new int[n]; pas[0] = 1;

System.out.println(pas[0]); for (int i = 2; i <= n; i++) {

/* 由存储在pas中的原来内容生成新内容*/ pas[i - l] =1;

for (int j = i- 2;j > 0; j--)

pas[j] = pas[j] + pas[j - 1 ]; for (int j = 0; j < i; j++)

System.out.print(pas[j] +" "); System.out.println(); } }

34.阅读下列程序,请用示意图画出程序运行时呈现的界面。

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

class MyPanel extends JPanel { JButton button; JLabel label; MyPanel(String s1, String s2) {

this.setLayout(new GridLayout(2, 2)); button = new JButton(s1);

label = new JLabel(s2, JLabel.CENTER);

add(button); add(label); add(new JLabel());

} }

public class Class1 {

public static void main(String args[]) {

JFrame mw = new JFrame("一个示意窗口"); mw.setSize(400, 250);

Container con = mw.getContentPane(); con.setLayout(new BorderLayout()); MyPanel panel1, panel2;

panel1 = new MyPanel("按钮1" ,"标签1"); panel2 = new MyPanel("按钮2", "标签2"); JButton button = new JButton("开始按钮");

con.add(panel1, "North");con.add(panel2, "South"); con.add(button, "Center"); mw.setVisible(true);

} }

35.阅读下列程序,请回答以下问题:

(1)程序要求在文本框text中输入的内容是什么? (2)辅助文本区showArea组件的作用是什么? (3)如何使程序开始下载网络文本文件? (4)程序采用什么输入方式下载网络文件?

import .*; import java.awt.*;

import java.awt.event.*; import,java.io.*; import javax.swing.*; public class Class1{

public static void main(String args[]) .

{ new ConnectNet("读取网络文本文件示意程序");} }

class ConnectNet extends JFrame implements ActionListener{ JTextField text=new JTextField(30); JTextArea showArea=new JTextArea();

JButton b=new JButton("下载");JPanel p=new JPanel(); ConnectNet(String s){

super(s);Container con=this.getContentPane(); p.add(text);p.add(b);

JScrollPane jsp=new JScrollPane(showArea); b.addActionListener(this);

con.add(p,"North"); con.add(jsp,"Center");

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(500,400);setVisible(true); }

public void actionPerformed(ActionEvent e){ String urlName=text.getText();

try{ 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+"\n");} dis.close();

}catch(MalformedURLException e2){e2.printStackTrace();} catch(IOException e3){ e3.printStackTrace();} } }

36..阅读下列程序,请写出该程序的功能。

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

public class Class1 extends java.applet.Applet implements Runnable { Thread myThread = null; public void start() { setSize(500, 400);

if (myThread == null) {

myThread = new Thread(this); myThread.start(); } }

public void run() {

while (myThread != null) {

try { myThread.sleep(500);

} catch (InterruptedException e) { } repaint();

}

}

public void paint(Graphics g) {

int x = (int)(400*Math.random()); int y = (int)(300*Math.random());

g.setColor(Color.red); g.fillOval(x,y, 10, 10);

} }

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

37.编写数组复制方法。该方法从已知平衡的两维数组的左下角复制出一个非平衡的三角二维数组。设复制数组方法的模型为:

public static double[][] leftDownConer(double[][]anArray) 38.设计实现以下形式布局的Java小应用程序。

注1:其中空白格是文本框,用于输入对应的内容。

注2:这里给出的是程序的一部分,你要编写的是方法MyWindow(String s)。 import java.applet.*; import javax.swing.*; import java.a …… 此处隐藏:2733字,全部文档内容请下载后查看。喜欢就下载吧 ……

04747Java语言程序设计(一)历年真题2(2).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/wenku/52647.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)