国产在线精品一级A片-国产另类欧美-国产精品va在线观看一-我要找美国一级片黄色|www.zheinei.com

Java語(yǔ)言程序設(shè)計(jì)試題及參考答案

java試題 時(shí)間:2017-04-21 我要投稿
【www.zheinei.com - java試題】

  Java語(yǔ)言程序設(shè)計(jì)介紹了Java語(yǔ)言的基本概念和編程方法,同時(shí)深入介紹了Java的高級(jí)特性。以下是由陽(yáng)光網(wǎng)小編整理關(guān)于Java語(yǔ)言程序設(shè)計(jì)試題的內(nèi)容,希望大家喜歡!

  Java語(yǔ)言程序設(shè)計(jì)試題

  一、單項(xiàng)選擇題(本大題共10小題,每小題1分,共10分) 在每小題列出的四個(gè)備選項(xiàng)中只有一個(gè)是符合題目要求的,請(qǐng)將其代碼填寫在題后的括號(hào)內(nèi)。錯(cuò)選、多選或未選均無(wú)分。

  1. 按運(yùn)算符操作數(shù)的數(shù)目劃分,運(yùn)算符 ? :的類型是() (1分)

  A:三目

  B:雙目

  C:四目

  D:?jiǎn)文?/p>

  2. Java代碼g.drawLine(100,100,100,100)的功能是() (1分)

  A:畫(huà)一個(gè)圓

  B:畫(huà)一條線段

  C:畫(huà)一個(gè)點(diǎn)

  D:代碼是錯(cuò)誤的

  3. Java中對(duì)數(shù)據(jù)庫(kù)查詢結(jié)果集進(jìn)行操作的對(duì)象是() (1分)

  A:Connection對(duì)象

  B:Statement對(duì)象

  C:DriverManager對(duì)象

  D:ResultSet對(duì)象

  4. 有關(guān)在Java中定義實(shí)例方法和類方法的敘述正確的是() (1分)

  A:前者有public修飾,后者沒(méi)有public修飾

  B:前者沒(méi)有public修飾,后者有public修飾

  C:前者有static修飾,后者沒(méi)有static修飾

  D:前者沒(méi)有static修飾,后者有static修飾

  5. 在Java語(yǔ)言中,一般不作為容器使用的是() (1分)

  A:JDialog

  B:JFrame

  C:JTextArea

  D:JPanel

  6. Java語(yǔ)言支持網(wǎng)絡(luò)通信的軟件都在()包中。 (1分)

  A:java.lang.net

  B:java.net

  C:java.net.ftp

  D:java.net.www

  7. 有Java語(yǔ)句如下,則說(shuō)法正確的是()

  int []a,b=new int[3]; (1分)

  A:此語(yǔ)句是錯(cuò)誤的

  B:a.length的值為3

  C:b.length的值為3

  D:a.length和b.length的值都為3

  8. 能處理鼠標(biāo)拖動(dòng)和移動(dòng)兩種事件的接口是() (1分)

  A:ActionListener

  B:ItemListener

  C:MouseListener

  D:MouseMotionListener

  9. Java語(yǔ)言的圖像處理功能所在的類是() (1分)

  A:Picture

  B:Image

  C:picture

  D:image

  10. 在Java語(yǔ)言中,支持網(wǎng)絡(luò)通信的軟件所在的包是() (1分)

  A:java.util

  B:java.net

  C:java.io

  D:java.internet

  二、填空題(本大題共10小題,每小題2分,共20分)請(qǐng)?jiān)诿啃☆}的空格中填上正確答案。錯(cuò)填、不填均無(wú)分。

  1. 在Java的某個(gè)組件中繪圖,一般應(yīng)該為這個(gè)組件所屬的子類重寫方法,在該重寫的方法中進(jìn)行繪圖。 (2分)

  2. Java語(yǔ)言提供兩個(gè)用于處理字符串的類:String類用于處理不可改變的字符串,類用于處理可改變的字符串。 (2分)

  3. 在Java程序中,設(shè)置文本區(qū)對(duì)象textA能自動(dòng)換行的方法是:。 (2分)

  4. Java程序要采用緩沖式輸入,需要先創(chuàng)建對(duì)象,再利用這個(gè)對(duì)象創(chuàng)建BufferedReader對(duì)象。 (2分)

  5. 以下代碼的輸出結(jié)果是。

  System.out.println(5>4==3<4); (2分)

  6. 在Java程序中有如下代碼,則輸出結(jié)果為。

  Integer x=23456;

  System.out.println(x.toString().substring(2,4)); (2分)

  7. Date類在Java語(yǔ)言的包中。 (2分)

  8. Java語(yǔ)言提供一個(gè)Graphics2D類,這個(gè)類定義了幾種方法用于添加或改變圖形的狀態(tài)屬性,其中屬性用來(lái)控制線條的寬度、筆形樣式、線段連接方

  式或短劃線圖案。 (2分)

  9. 設(shè)定文本框?qū)ο髏ext使其不可編輯對(duì)應(yīng)的代碼是。 (2分)

  10. 由于sleep()方法可能產(chǎn)生異常,應(yīng)將sleep()方法寫在try塊中,并用catch塊處理異常。 (2分)

  三、程序填空題(本大題共5小題,每空2分,共20分)

  1. 下面小應(yīng)用程序啟動(dòng)后自動(dòng)播放一個(gè)聲音文件。

  import java.applet.*;

  public class Class3001

  {

  public void start()

  {

  AudioClip clip=(getCodeBase(),"2.wav");

  clip.play();

  }

  } (2分)

  2. 以下程序產(chǎn)生一個(gè)依賴myWin,標(biāo)題為“我的對(duì)話框”的,布局管理器為FlowLayout的強(qiáng)制型對(duì)話框。

  import java.awt.*;

  import javax.swing.*;

  public class Class29041

  {

  public static void main(String[] args)

  {

  JFrame myWin=new JFrame();

  JButton button=new JButton("butt");

  myDialog.add(button);

  myDialog.setBounds(300,300,200,200);

  myDialog.setVisible(true);

  }

  } (2分)

  3. 以下程序產(chǎn)生一個(gè)確認(rèn)對(duì)話框。

  import javax.swing.*;

  public class Class2905

  {

  public static void main(String[] args)

  {

  JFrame myWin=new JFrame();

  myWin.setBounds(100,100,200,300);

  myWin.setVisible(true);

  myWin.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

  int resule=.(myWin, "確實(shí)要退出嗎?","退出確認(rèn)",0);

  System.out.println(resule);

  }

  } (2分)

  4. 下面程序段是用Thread子類實(shí)現(xiàn)多線程(其中ThreadB與ThreadA非常相似,未給出)。

  import java.util.Date;

  public class Class3105

  {

  class ThreadA extends Thread

  {

  public void run()

  {

  Date timeNow;

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

  {

  timeNow=new Date();

  System.out.println("A"+timeNow.toString());

  try{sleep(2000);}

  catch(InterruptedException e){}

  }

  }

  }

  class ThreadB extends Thread

  {…………

  …………

  }

  public Class3105()

  {

  ThreadA threadA=

  ThreadB threadB=new ThreadB();

  threadA.start();

  }

  public static void main(String[] args)

  {

  new Class3105();

  }

  } (2分)

  5. 設(shè)計(jì)一個(gè)面板,該面板中有四個(gè)運(yùn)動(dòng)項(xiàng)目單選按鈕和一個(gè)文本框。當(dāng)某個(gè)選擇項(xiàng)目被選中時(shí),在文本框中顯示該選擇項(xiàng)目。請(qǐng)完成程序。

  import java.applet.*;

  import java.awt.*;

  import javax.swing.*;

  import java.awt.event.*;

  public class C2901 extends Applet implements ItemListener

  {

  ;

  String s[]={"足球","排球","籃球","乒乓球"};

  JRadioButton box[]=new JRadioButton[4];

  JTextField text=new JTextField(20);

  public void init()

  {

  setSize(400,70);

  ButtonGroup group=new ButtonGroup();

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

  {

  box[i]=new JRadioButton(s[i]);

  group.add(box[i]);

  pan.add(box[i]);

  box[i].addItemListener(this);

  }

  add(pan);

  add(text);text.setBackground(Color.cyan);

  }

  public void(ItemEvent e)

  {

  text.setText("你選擇了:"

  +((JRadioButton)e.getItemSelectable()).getText());

  }

  } (2分)

  四、程序分析題(本大題共5小題,每小題4分,共20分)

  1. 閱讀下面程序,寫出程序功能及當(dāng)輸入6和9時(shí)的運(yùn)行情況。

  import java.awt.*;

  import javax.swing.*;

  import java.awt.event.*;

  public class Class3402 implements ActionListener

  {

  JButton butt=new JButton("OK");

  JTextField text1=new JTextField(10);

  JTextField text2=new JTextField(10);

  JTextField text3=new JTextField(10);

  public Class3402()

  {

  JFrame myWin=new JFrame("Class3402");

  myWin.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

  Container con=myWin.getContentPane();

  con.setLayout(new GridLayout(4,1));

  con.add(text1);con.add(text2);

  con.add(butt);con.add(text3);

  butt.addActionListener(this);

  myWin.pack();

  myWin.setVisible(true);

  }

  public void actionPerformed(ActionEvent e)

  {

  int a=Integer.parseInt(text1.getText());

  int b=Integer.parseInt(text2.getText());

  int i;

  for(i=1;i<=a*b;i++)

  {

  if(i%a==0&&i%b==0)break;

  }

  text3.setText(String.valueOf(i));

  }

  public static void main(String[]args)

  {

  new Class3402();

  }

  } (4分)

  2. 閱讀下列程序,寫出程序功能。

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

  import java.awt.event.*;

  public class Class36004 extends Applet implements KeyListener

  {

  int count=0;

  TextArea text=new TextArea(5,20);

  public void init()

  {

  add(text);

  text.addKeyListener(this);

  }

  public void keyPressed(KeyEvent e)

  {

  int t =e.getKeyCode();

  if(t>=KeyEvent.VK_0 && t<=KeyEvent.VK_9)

  {

  text.append("*");count ++;

  if(count %10==0) text.append("\n");

  }

  else

  text.setEditable(false);

  }

  public void keyTyped(KeyEvent e){}

  public void keyReleased(KeyEvent e){}

  } (4分)

  3. 閱讀下列程序,寫出程序功能。

  import java.awt.*;

  import javax.swing.*;

  import java.awt.event.*;

  public class C3401 implements ActionListener

  {

  JFrame frmFrame;

  JButton btnUp, btnDown;

  public C3401()

  {

  frmFrame = new JFrame("按鈕應(yīng)用");

  frmFrame.setLayout(new GridLayout(2,1));

  btnUp = new JButton("上");

  btnUp.setActionCommand("btnUp");

  btnUp.addActionListener(this);

  btnDown = new JButton("下");

  btnDown.setActionCommand("btnDown");

  btnDown.addActionListener(this);

  frmFrame.add(btnUp);

  frmFrame.add(btnDown);

  frmFrame.pack();

  frmFrame.setVisible(true);

  }

  public void actionPerformed(ActionEvent e)

  {

  String cmd = e.getActionCommand();

  if ( cmd.equals("btnDown") )

  if (btnUp.getBackground()==Color.BLUE)

  btnUp.setBackground(Color.red);

  else

  btnUp.setBackground(Color.blue);

  else

  if (btnDown.getBackground()==Color.BLUE)

  btnDown.setBackground(Color.red);

  else

  btnDown.setBackground(Color.blue);

  }

  public static void main(String[] args)

  {

  new C3401();

  }

  } (4分)

  4. 閱讀下列程序,寫出程序運(yùn)行結(jié)果。

  class A

  {

  int x,y;

  A(int xx,int yy){x=xx;y=yy;}

  }

  interface A3202{int f3202(A a);}

  interface B3202{int g3202();}

  public class C3202 extends A implements A3202,B3202

  {

  A a=new A(x,y);

  C3202(int x,int y)

  {

  super(x,y);

  this.x=x*x;

  this.y=y*y;

  }

  public int f3202(A a){return x*a.x+x*a.y;}

  public int g3202(){return x*a.x+x*a.y;}

  public static void main(String[] args)

  {

  int x=10,y=20;

  A a=new C3202(x,y);

  C3202 c=new C3202(x,y);

  System.out.println(a.x+","+a.y);

  System.out.println(c.f3202(a));

  System.out.println(c.g3202());

  }

  } (4分)

  5. 閱讀下列程序,寫出程序功能。

  import java.awt.*;

  import java.applet.*;

  import javax.swing.*;

  import java.awt.event.*;

  public class C3402 extends Applet

  {

  static JFrame myWin;

  static SetBG setbg=new SetBG();

  static JButton button;

  public void init()

  {

  myWin=new JFrame("C3402");

  myWin.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

  myWin.setBounds(100,200,300,400);

  myWin.setLayout(new FlowLayout());

  Container con=myWin.getContentPane();

  con.setBackground(Color.red);

  button=new JButton("OK");

  button.addActionListener(setbg);

  myWin.add(button);

  myWin.setVisible(true);

  }

  }

  class SetBG implements ActionListener

  {

  public void actionPerformed(ActionEvent e)

  {

  Container con=C3402.myWin.getContentPane();

  if (con.getBackground()==Color.red)

  con.setBackground(Color.green);

  else

  con.setBackground(Color.red);

  }

  } (4分)

  五、程序設(shè)計(jì)題(本大題共2小題,每小題6分,共12分)

  1. 編寫一個(gè)方法array3702(),要求該方法有一個(gè)元素類型為int的數(shù)組參數(shù),方法返回一個(gè)新數(shù)組,新數(shù)組的長(zhǎng)度與參數(shù)數(shù)組的長(zhǎng)度相同,而

  新數(shù)組元素的值是參數(shù)數(shù)組各元素的一半。 (6分)

  2. 編寫一個(gè)方法string3703,要求在一個(gè)字符串?dāng)?shù)組中找出長(zhǎng)度最短的一個(gè)元素。其中字符串?dāng)?shù)組是方法的參數(shù),最短的一個(gè)元素是方法的

  返回值。 (6分)

  六、簡(jiǎn)答題(本大題共6小題,每小題3分,共18分)

  1. 請(qǐng)解釋clipRect(int x,int y,int w,int h)方法的功能及參數(shù)含義。 (3分)

  2. 請(qǐng)寫出表示條件“x=2與y=3最多只有一個(gè)成立”的Java表達(dá)式。 (3分)

  3. 一個(gè)網(wǎng)絡(luò)關(guān)系數(shù)據(jù)庫(kù)應(yīng)用系統(tǒng)是一個(gè)三層次結(jié)構(gòu),請(qǐng)寫出這三個(gè)層次結(jié)構(gòu)。 (3分)

  4. 標(biāo)簽(JLabel)是最簡(jiǎn)單的Swing組件,程序關(guān)于標(biāo)簽的基本內(nèi)容有哪三個(gè)方面? (3分)

  5. JDBC是Java程序與數(shù)據(jù)庫(kù)連接的API,請(qǐng)寫出它能做哪三件事? (3分)

  6. 程序中要使用文件對(duì)話框打開(kāi)和保存文件,應(yīng)該用哪個(gè)包中的哪個(gè)類來(lái)實(shí)現(xiàn)? (3分)

下一頁(yè)更多有關(guān)“Java語(yǔ)言程序設(shè)計(jì)試題及參考答案”的內(nèi)容

熱門文章