计算机类
公务员类
工程类
语言类
金融会计类
计算机类
医学类
研究生类
专业技术资格
职业技能资格
学历类
党建思政类
计算机等级考试(NCRE)
全国计算机应用水平考试(NIT)
计算机软件水平考试
计算机等级考试(NCRE)
全国高校计算机等级考试CCT
行业认证
信息素养
计算机等级考试二级
计算机等级考试一级
网络工程师(计算机等级考试四级)
计算机等级考试二级
数据库工程师(计算机等级考试四级)
计算机等级考试三级
信息安全工程师(计算机等级考试四级)
嵌入式系统开发工程师(计算机等级考试四级)
软件测试工程师(计算机等级考试四级)
Java语言程序设计
Python语言程序设计
WPS Office高级应用与设计
C语言程序设计
C++语言程序设计
Java语言程序设计
Visual Basic语言程序设计
Web程序设计
Access数据库程序设计
MySQL数据库程序设计
Visual FoxPro数据库程序设计
办公软件高级应用
问答题本程序中,不同类型的操作数间进行运算。其中,a为字符型变量且值为"1",b为整型变量且值为7,c为双精度浮点型变量且值为7.9。程序中将a与b求和后结果赋给字符型变量d,b与c求和后结果赋给整型变量e,a与c求和后结果赋给字符型变量f。 public class exam_86{ public static void main(String[] args) { char a="1"; int b=7; double c=7.9; char d=______(a+b); int e=______(b+c); char f=______(a+c); System.out.println("d="+d); System.out.println("e="+e); System.out.println("f="+f); } }
进入题库练习
问答题本题的功能是计算二维数组arr[][]={{34,21,45,67,20),{23,10,3,45,76},{22,3,79,56,50}}中的最小值,并输出。
进入题库练习
问答题本题程序的功能是监听对于列表项的操作。窗口中有一个列表和“添加”、“删除”和“关闭”三个按钮。单击“添加”按钮,会在当前所选列表项后添加一个名为“新增表项”的列表项,同时后台输入列表中的表项数量。单击“删除”按钮,如果未选中表项,则弹出提示消息框“请选择表项”,否则将选中的表项删除,同时后台输出删除表项的内容和列表中的表项数量。单击“关闭”按钮退出程序。程序中存在若干错误,请找出并改正(注意:不得改动程序的结构,不得增行或删行)。 import java.awt.*; import java.awt.event.*; import javax.swing.JOptionPane; public class advance { public static void main(String args[]) { final Frame frmFrame = new Frame(); Panel pnlPanel1 = new Panel(); Panel pnlPanel2 = new Panel(); final List istList = new List(8); for(int i = 0; i <10; i++) { String strName = "表项" + (new Integer(i+1)).toString(); istList.add( strName ); } Button btnButton1 = new Button("添加"); Button btnButton2 = new Button("删除"); Button btnButton3 = new Button("关闭"); btnButton1.addActionListener( new ActionListener() { publiC void actionPerformed(ActionEvent e) { lstList.add("新增表项",istList.getSelected()+1); System.out.println("列表中的表项数量" + istList,getItemCount() ); } }); btnButton2.addActionListener (new ActionListener () { public void actionPerformed(ActionEvent e) { if(istList.getSelected() == null) { JOptionPane.showMessageDialog(frmFrame,"请选择表项"); return; } System.out.println("删除表项的内容:"+ istList,getSelectedItem()); istList.delete(istList.getSelectedIndex()); System.out.println("列表中的表项数量: " + istList,getItemCount ()); } }); btnButton3.addActionListener(new ActionListener () { public void actionPerformed(ActionEvent e) { System.exit (0); } }); pnlPanel1 .add (istList); pnlPanel2 .add (btnButton1); pnlPanel2 .add (btnButton2); pnlPanel2,add (btnButton3); frmFrame.add("North",pnlPanel1); frmFrame.add("South",pnlPanel2); frmFrame,setTitle ("advance"); frmFrame.pack (); frmFrame,show (); } }
进入题库练习
问答题下面是一个Applet程序,其功能是用一组坐标点绘制一个多边形,并通过沿坐标的垂直方向移动,把它移到窗口的下半部分,然后填充它。请改正程序中的错误(有下画线的语句),使程序能输出正确的结果。 注意:不改动程序的结构,不得增行或删行。 import java.awt.*; import java.applet.*; /* <applet code="ex16_3.class"width=800 height=400> </applet> */ public class ex16_3 extends Applet{ int[] x={15,50,100,160,120,190}; int[] y={15,100,30,15,80,50 }; public void init(){ setBackground(Color.lightGray); { public void paint(Craphics g){ int[]y2=new int[6]; g.setColor(Color.red); Rectangle rect=getBounds(); {{U}}g.drawPolygon(x,y2,6);{{/U}} for(int i=0;i<6;i++) {{U}}Y2[i]=y[i]+(rect.height/2);{{/U}} {{U}}g.fillPolygon(x,y,6);{{/U}} } } ex16_3.html <HTML> <HEAD> <TITLE>ex16_3</TITLE> </HEAD> <BODY> <applet code='ex16_3.class"width=800 height=400> </applet> </BODY> </HTML>
进入题库练习
问答题本题定义了一个方法add(),用于求两个整形数的和。方法中有两个整形参数a和b,方法体中计算a和b的和sum,并将结果返回。程序中调用add()方法求整数24和34的和,并将结果打印输出。   public class javal{   public static void main(String[]args){   int a=24,b=34;   System.out.println(add(a,b));   }   public static int add( ){    ;   sum—a+b;    ;   }   }
进入题库练习
问答题本题程序的功能是:主窗口中有一个按钮,按钮的长和宽每200ms增加1,当达到100时又恢复原来大小重新进行增加。请将下述程序补充完整(注意:不得改动程序的结构,不得增行或删行)。 import java.awt.*; import java.awt.event.*; public class simple public static void main (String args[]) Mywin win = new Mywin(); class Mywin extends Frame ______ Button b = new Button("按钮");int x = 5; Thread bird = null; Mywin () setBounds(100,100,400,400); setLayout(new FlowLayout()); setTitle ("simple"); setVisible (true); add(b); b.setBackground (Color.green); addWindowListener (new WindowAdapter () public void windowClosing(WindowEvent e) System.exit (0); ); bird = new Thread(this); bird.start(); public ______ while (true) x = x+1; if(x > 100) x = 5; b.setBounds(40,40,x,x); try bird.sleep (200); catch(InterruptedException e)
进入题库练习
问答题本题使用下拉菜单来控制字体,窗口中有一个标签和一个下拉菜单,当选中下拉菜单中的任一项字体时,标签上字符串的字体就随之改变。 import java.awt.*; import java.awt.event.*; import javax.swing.*; class ComboBoxFrame extends JFrame______ public ComboBoxFrame() setTitle("java2"); setSize(300,200); addWindowListener(new WindowAdapter() public void windowClosing(WindowEvent e) System.exit(0); ); style=new JComboBox(); style.setEditable(true); style.addItem("Serif"); style.addItem("SansSerif"); style.addItem("Monospaced"); style.addItem("Dialog"); style.addItem("DialogInput"); style.addActionListener(this); JPanel p=new JPanel(); p.add(style); getContentPane().add(p,"South"); panel=new ComboBoxTestPanel(); getContentPane().add(panel,"Center"); public void actionPerformed(ActionEvent evt) JComboBox source=(JComboBox)______; String item=(String)source.getSelectedItem(); panel.setStyle(item); private ComboBoxTestPanel panel; private JComboBox style; class ComboBoxTestPanel extends JPanel public ComboBoxTestPanel() setStyle("Serif"); public void setStyle(String s) setFont(new Font(s,Font.PLAIN,12)); repaint(); public void paintComponent(Graphics g) super.paintComponent(g); g.drawstring("Welcome to China!",0,50); public class java2 public static void main(String[]args) JFrame frame=new ComboBoxFrame(); frame.show();
进入题库练习
问答题下面的程序的功能是将数组array下标为奇数的元素相乘(数组的位置是从0开始的),并将乘积存放到变量total中。请在程序的每条横线处填入适当的语句,使程序的功能完整。 注意:请勿改动main()主方法和其他已有的语句内容,仅在横线处填入适当的语句。 public class JiShuJi { public static void main(String args[ ]) { int array[ ]={1,2,3,5,7,9}; long total= ________________________; for(int i=1;i<=__________________ i++) { ____________________ i++; } System.out.println(total); } }
进入题库练习
问答题下面是一个Applet程序,其功能是通过一个按钮控制一个窗口的创建,显示与隐藏,并且以按钮文字作为提示,可以随着窗口的状态改变,即如果窗口出现,则按钮文字为Hide myFrm,提示用户点击按钮,则隐藏窗口,反之亦然。请改正程序中的错误(有下划线的语句),使程序能输出正确的结果。 注意:不改动程序的结构,不得增行或删行。 源程序代码文件清单如下; import java.awt.*; import java.applet.*; /* <applet code="ex20_3.class"width=800 height=400> </applet> */ public class ex20_3 extends Applet private Frame frm; private Button showBtn; public void init() showBtn=new Button("Show Frame"); add(ShowBtn); public boolean action(Event e,Object o) ife.target==showBtn) if(frm==null) frm,show(); frm.dispose(); frm=null; showBtn.setLabel("Show myFrm"); else frm=new Frame("myFrm"); frm.resize(200,150); frm.setBackground(Color.gray); frm.hide(); showBtn.SetLabel("Hide myFrm"); return true; ex02_3.html <HTML> <HEAD> <TITLE>ex02_3</TITLE> </HEAD> <BODY> <applet code="ex02_3.class" width=800 height+400> </applet> </BODy> </HTML>
进入题库练习
问答题本题的功能是对图形进行操作,包括旋转、移位、放大和剪切。窗口中有4个单选按钮和一个图形面板,图形面板中有一个矩形和该矩形移位操作后的图形,任选其中一个单选按钮,则图形面板中将显示该操作后的图形。 import java.awt.*; import java.awt.event.*; import java.awt.geom.*; import java.util.*; import javax.swing.*; public class java3 public static void main(String[]args) JFrame frame=new TransformTestFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.show(); class TransformTest extends JFrame public TransformTestFrame() setTitle("java3"); setSize(WIDTH,HEIGHT); Container contentPane=getContentPane(); canvas=new TransformPanel(); contentPane.add(canvas,BorderLayout,CENTER); JPanel buttonPanel=new JPanel(); ButtonGroup group=new ButtonGroup(); JRadioButton rotateButton =new JRadioButton("旋转",true); buttonPanel.add(rotateButton); group.add(rotateButton); rotateButton.addActionListener(new ActionListener() public void actionPerformed(ActionEvent event) canvas.setRotate(); ); JRadioButton translateButton =new JRadioButton("移位",false); buttonPanel.add(translateButton); group.add(translateButton); translateButton.addActionListener(new ActionListener() public void actionPerformed(ActionEvent event) canvas.setTranslate(); ); JRadioButton scaleButton =new JRadioButton("放大",false); buttonPanel.add(scaleButton); group.add(scaleButton); scaleButton.addActionListener(new ActionListener() public void actionPerformed(ActionEvent event) canvas.setScale(); ); JRadioButton shearButton =new JRadioButton("剪切",false); buttonPanel.add(shearButton); group.add(shearButton); shearButton.addActionListener(new ActionListener() public void actionPerformed(ActionEvent event) canvas.setShear(); ); contentPane.add(buttonPanel,BorderLayout.NORTH) private TransformPanel canvas; private static final int WIDTH=300; private static final int HEIGHT=300; class TransformPanel extend JPanel public TransformPanel() square=new Rectangle2D.Double(-50,-50,100,100); t=flew AffineTransform(); setRotate(); public void paintComponent() super.paintComponent(g); Graphics2D g2=(Graphics2D)g; g2.translate(getWidth()/2,getHeight()/2); g2.setPaint(Color.gray); g2.draw(square); g2.transform(t); g2.setPaint(Color.black); g2.draw(square); public void setRotate() t.setToRotation(Math.toRadians(30)); repaint(); public void setTranslate() t.setToTranslation(20,15); repaint(); public void setScale() t.setToScale(2.0,1.5); repaint(); public void setShear() t.setToShear(-0.2,0); repaint(); private Rectangle2D square; private AffineTransform t;
进入题库练习
问答题本程序的功能是用菜单控制字符串的显示。窗口中有“File”和“Format”菜单,“File”中有“About”和“Exit”菜单项,单击“About”菜单项弹出一个消息对话框,单击“Exit”菜单项退出程序。“Format”菜单中有“Color”和“Font”菜单项,“Color”菜单项的子菜单项用来设置字符串的颜色,“Font”菜单项的子菜单项用来设置字符串的样式,如图所示。importjavax.swing.*;importjava.awt.event.*;importjava.awt.*;publicclassexam_85extendsJFrame{privateColorcolorValues[]={Color.black,Color.blue,Color.red,Color.green};privateJRadioButtonMenuItemcolorItems[],fonts[];privateJCheckBoxMenuItemstyleItems[];privateJLabeldisplay;privateButtonGroupfontGroup,colorGroup;privateintstyle;publicexam_85(){super("exam_85");JMenuBarbar=newJMenuBar();setMenuBar(bar);JMenufileMenu=newJMenu("File");fileMenu.setMnemonic("F");JMenuItemaboutItem=newJMenuItem("About...");aboutItem.setMnemonic("A");aboutItem.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){JOptionPane.showMessageDialog(exam_85.this,"Thisisanexample/nofusingmenus","About",JOptionPane.PLAIN_MESSAGE);}});fileMenu.add(aboutItem);JMenuItemexitItem=newJMenuItem("Exit");exitItem.setMnemonic("x");exitItem.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){System.exit(0);}});fileMenu.add(exitItem);bar.add(fileMenu);JMenuformatMenu=newJMenu("Format");formatMenu.setMnemonic("r");Stringcolors[]={"Black","Blue","Red","Green"};JMenucolorMenu=newJMenu("Color");colorMenu.setMnemonic("C");colorItems=newJRadioButtonMenuItem[colors.length];colorGroup=newButtonGroup();ItemHandleritemHandler=newItemHandler();for(inti=0;i<colors.length;i++){colorItems[i]=newJRadioButtonMenuItem(colors[i]);colorMenu.add(colorItems[i]);colorGroup.add(colorItems[i]);colorItems[i].addActionListener(itemHandler);}colorItems[0].setSelected(true);formatMenu.add(colorMenu);formatMenu.addSeparator();StringfontNames[]={"TimesRoman","Arial","Helvetica"};JMenufontMenu=newJMenu("Font");fontMenu.setMnemonic("n");fonts=newJRadioButtonMenuItem[fontNames.length];fontGroup=newButtonGroup();for(inti=0;i<fonts.length;i++){fonts[i]=newJRadioButtonMenuItem(fontNames[i]);fontMenu.add(fonts[i]);fontGroup.add(fonts[i]);fonts[i].addActionListener(itemHandler);}fonts[0].setSelected(true);fontMenu.addSeparator();StringstyleNames[]={"Bold","Italic"};styleItems=newJCheckBoxMenuItem[styleNames.length];StyleHandlerstyleHandler=newStyleHandler();for(inti=0;i<styleNames.length();i++){styleItems[i]=newJCheckBoxMenuItem(styleNames[i]);fontMenu.add(styleItems[i]);styleItems[i].addItemListener(styleHandler);}formatMenu.add(fontMenu);bar.add(formatMenu);display=newJLabel("SampleText",SwingConstants.CENTER);display.setForeground(colorValues[0]);display.setFont(newFont("TimesRoman",Font.PLAIN,72));getContentPane().setBackground(Color.white);getContentPane().add(display,BorderLayout.CENTER);setSize(500,200);show();}publicstaticvoidmain(Stringargs[]){exam_85app=newexam_85();app.addWindowListener(newWindowAdapter(){publicvoidwindowClosing(WindowEvente){System.exit(0);}});}classItemHandlerimplementsActionListener{publicvoidactionPerformed(ActionEvente){for(inti=0;i<colorItems.length;i++)if(colorItems[i].isSelected()){display.setForeground(colorValues[i]);break;}for(inti=0;i<fonts.length;i++)if(e.getSource()==fonts[i]){display.setFont(newFont(fonts[i].getText(),style,72));break;}repaint();}}classStyleHandlerimplementsItemActionListener{publicvoidStemStateChanged(ItemEvente){style=0;if(styleItems[0].isSelected())style+=Font.BOLD;if(styleItems[1].isSelected())style+=Font.ITALIC;display.setFont(newFont(display.getFont().getName(),style,72));repaint();}}}
进入题库练习
问答题请完成下列Java程序:生成一个窗口,包含一个长度为100的横向滚动条,实现对这个滚动条状态的监视,计算出滚动条的位置在整个长度的百分比,并通过画布将该值输出在滚动条上方的区域中。注意:请勿改动main()主方法和其他已有语句内容,仅在下划线处填入适当的语句。程序运行结果如下:importjava.awt.*;importjava.awt.event.*;publicclassex19_2extendsFrameimplementsAdjustmentListener{privateScrollbarsb;privatemsgWndmw;privateintval;publicstaticvoidmain(String[]arg){ex19_2obj19_2=newex19_2();}publicex19_2(){setTitle("ex19_2");addWindowListener((WindowListener)newwinListener());mw=newmsgWnd();add("Center",mw);sb=newScrollbar(Scrollbar.HORIZONTAL);sb.setVisibleAmount(10);sb.setBlockIncrement(6);sb.setUnitIncrement(5);sb.addAdjustmentListener(this);add("South",sb);pack();show();}publicvoidadjustmentValueChanged(AdjustmentEventae){val=ae.getValue();_______________;}classmsgWndextendsCanvas{msgWnd(){setSize(450,20);}publicvoidpaint(Graphicsg)(g.drawString("val="+____________________+"%",10,15);}}classwinListenerextendsWindowAdapter{publicvoidwindowClosing(WindowEventwe){System.exit(0);}}}
进入题库练习
问答题本程序的功能是捕获通过“保存文件话框”和“打开文件话框”所选中的文件名称。程序窗口中有一个“文件”菜单和一个文本域,“文件”菜单中包括“保存文件”和“打开文件”菜单项,单击“保存文件”或“打开文件”菜单项,就会弹出一个“保存文件话框”或“打开文件话框”,退出该对话框后,将在文本域中显示所单击的菜单和所选文件的名称,如图所示。importjava.awt.*;importjava.awt.event.*;publicclassexam_88{publicstaticvoidmain(Stringargs[]){FWindowf=newFWindow("exam_88");}}classFWindowextendsFrameimplementsActionListener{FileDialogfiledialogsave,filedialog_load;MenuBarmenubar;Menumenu;MenuItemitemSave,itemLoad;TextAreatext;FWindow(Strings){super(s);setSize(300,400);setVisible(true);text=newTextArea(10,10);add(text,"Center");validate();menubar=newMenuBar();menu=newMenu("文件");itemSave=newMenuItem("保存文件");itemLoad=newMenuItem("打开文件");itemSave.addActionListener(this);itemLoad.addActionListener(this);menu.add(itemSave);menu.add(itemLoad);menubar.add(menu);setMenuBar(menubar);filedialog_save=newFilemialog(this,"保存文件话框",______);filedialogsave.setVisible(false);filedialog_load=newFilemialog(this,"打开文件话框",FileDialog.LOAD);filedialogload.setVisible(false);filedialogsave.addWindowListener(newWindowAdapter(){publicvoidwindowClosing(WindowEvente){filedialog_save.setVisible(false);}});filedialog_load,addWindowListener(newWindowAdapter(){publicvoidwindowClosing(WindowEvente){filedialogload.setVisible(false);}});addWindowListener(newWindowAdapter(){publicvoidwindowClosing(WindowEvente){setVisible(false);System.exit(0);}});}publicvoidactionPerformed(ActionEvente){if(e.getSource()==itemSave){filedialog_save,setVisible(true);Stringname=______;if(name!=null){text.setText("你选择了保存文件,名字是"+name);}else{text.setText("没有保存文件");}}elseif(e.getSource()==itemLoad){filedialog_load,setVisible(true);Stringname=filedialogload.getFile();if(name!=null){text.setText("你选择了打开文件,名字是"+name);}else{text.setText("没有打开文件");}}}}
进入题库练习
问答题下面Applet程序的功能是统计在平面坐标系中第一象限中,半径大于9,小于10的圆环中坐标值为整数的点有多少?并且给出其坐标值.请改正程序中的错误(有下划线的语句),使程序执行后,能得到预期的结果。注意:不改动程序的结构,不得增行或删行。程序的执行结果为:importjava.awt.*;importjava.applet.*;/*<appletcode=Di9Tiwidth=200height=100></applet>*/pubicclassDi9TiextendsAppletpublicvoidpaint(Graphicsg)intx,y,r1=5,r2=4;intcount=0;for(x=1;x<y;x++)for(y=1;y<r1;y)if(x*x+y*y<=r2*r2||x*x+y*y>=r1*r1)break;g.drawString("x="+x+"y="+y,20+count*80,20);count++;g.drawstring("count="+count,20,40);ex38_3.html:<html><head><title>ASimpleProgram</title></head><body><appletcode="Di9Ti.class"width=800height=400></applet></body></html>
进入题库练习
问答题本程序中,主窗口有一个按钮、一个文本域和一个复选框,初始时窗口的大小是不能调整的,选中复选框后,窗口大小就可以进行调整,如果撤销复选框的选择,则窗口的大小不能调整,单击按钮可以关闭程序,如图所示。importjava.awt.*;importjava.awt.event.*;classMyFrameextendsFrame______{Checkboxbox;TextAreatext;Buttonbutton;MyFrame(Strings){super(s);box=newCheckbox("设置窗口是否可调整大小");text=newTextArea(12,12);button=newButton("关闭窗口");button.addActionListener(this);box.addItemListener(this);setBounds(100,100,200,300);setVisible(true);add(text,BorderLayout.CENTER);add(box,BorderLayout.SOUTH);add(button,BorderLayout.NORTH);______;validate();}publicvoiditemStateChanged(ItemEvente){if(box.getState()==true){setResizable(true);}else{setResizable(false);}}publicvoidactionPerformedActionEvente){dispose();}}classexam_82{publicstaticvoidmain(Stringargs[]){newMyFrame("exam_82");}}
进入题库练习
问答题本程序的功能是获取文本框中的文本。窗口中有两个文本框:“用户名”和“密码”,以及三个按钮:“登录”、“其他用户登录”和“关闭”,初始状态“用户名”文本框是只读的,单击“其他用户登录”按钮后变成可写的,“密码”文本框使用的不是密码文本框,在用户键入时设置显示为“*”。输入用户名和密码,单击“登录”按钮后,如果输入的密码为空,则弹出提示消息框,否则后台将显示输入的用户名和密码。例如显示为“abc用户的密码:123”(abc为输入的用户名,123为输入密码),如图所示。importjava.awt.*;importjava.awt.event.*;importjavax.swing.JOptionPane;publicclassexam_4{publicstaticvoidmain(Stringargs[]){finalFramefrmFrame=newFrame();PanelpnlPanel=newPanel();LabellblUsername=newLabel("用户名");LabellblPassword=newLabel("密码");finalTextFieldtxtUsername=newTextField("Anyomonus");finalTextFieldtxtPassword=newTextField(,8);txtUsername.setEditable(false);txtPassword.setChar("*");ButtonbtnButton1=newButton("登录");ButtonbtnButton2=newButton("其他用户登录");ButtonbtnButton3=newButton("关闭");btnButton1.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){if((txtPassword.getText()).length()==0){JOptionPane.showMessageDialog(frmFrame,"密码不能为空");return;}txtPassword,setColumns(16);System.out.println(txtUsername.getText()+"用户的密码:"+txtPassword.getPassword()__);}});btnButton2.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){txtUsername.setEnable(true);}});btnButton3.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){System.exit(0);}});pnlPanel.add(iblUsername);pnlPanel.add(txtUsername);pnlPanel.add(iblPassword);pnlPanel.add(txtPassword);pnlPanel.add(btnButton1);pnlPanel.add(btnButton2);pnlPanel.add(btnButton3);frmFrame.add(pnlPanel);frmFrame.setTitle("exam_4");frmFrame.pack();frmFrame.show();}}
进入题库练习
问答题本程序定义了一个简单的计算器,可以进行基本的四则运算。程序中布局了16个按钮用来表示0~9以及运算符和点号,程序顶部的文本框用来显示运算数及结果,如图所示。importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;publicclassexam_61{publicstaticvoidmain(String[]args){try{UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());}catch(Exceptione){}JFrameframe=newCalculatorFrame();frame.show();}}classCalculatorPanelextendsJPanelimplementsActionListener{privateJTextFielddisplay;privateJButtonbtn;privatedoublearg=0;privateStringop="=";privatebooleanstart=true;publicCalculatorPanel(){setLayout(newBorderLayout());display=newJTextField("0");display.setEditable(false);add(display,"North");JPanelp=newJPanel();p.setLayout(newGridLayout(4,4));Stringbuttons="789/456*123-0.=+";for(inti=0;i<buttons.length();i++){btn=newJButton(buttons.substring(i,i+i));p.add(btn);______;}add(p,"Center");}publicvoidactionPerformed(ActionEventevt){Strings=evt.getActionCommand();if("0"<=s.charAt(0)elsedisplay.setText(display.getText()+s);start=false;}else{if(start){if(s.equals("_")){display.setText(s);start=false;}elseop=s;}else{doublex=______;calculate(x);op=s;start=true;}}}publicvoidcalculate(doublen){if(op.equals("+"))arg+=n;elseif(op.equals("_"))arg-=n;elseif(op.equals("*"))arg*=n;elseif(op.equals("/"))arg/=n;elseif(op.equals("="))arg=n;display.setText(""+arg);}}classCalculatorFrameextendsJFrame{publicCalculatorFrame(){setTitle("exam_61");setSize(220,180);addWindowListener(newWindowAdapter(){publicvoidwindowClosing(WindowEvente){System.exit(0);}});ContainercontentPane=getContentPane();contentPane.add(newCalculatorPanel());}}
进入题库练习
问答题catch(________________________e)
进入题库练习
问答题下面是一个Applet程序,其功能是打印一个任意进制的乘法表。要求输入乘法表的进制,点击ok则打印出该乘法表。请改正程序中的错误(有下划线的语句),使程序能输出正确的结果。注意:不改动程序的结构,不得增行或删行。程序运行结果如下:importjava.awt.*;importjava.applet.*;importjava.lang.*;publicclassex303extendsApplet{privateTextFieldtf;privateButtonbtn;publicvoidinit(){tf=newTextField(25);add(tf);btn=newButton("OK");add(btn);resize(250,200);}publicvoidpaint(Graphicsg){try{intn={{U}}tf.getText(){{/U}};inti,j,x=20,y=60;for({{U}}i=0;i<n;i++{{/U}}){for(j=1;j<=n;j++){g.drawString(Integer.toString(i)+"*"+Integer.toString(j)+"="+Integer.toString(i*j),{{U}}i*x,j*y{{/U}});}}}catch(NumberFormatExceptionnfe){g.drawString("errornumber!",20,50);}}publicbooleanaction(Evente,Objecto){if(o=="OK"){repaint();returntrue;}elsereturnfalse;}}{{B}}ex30_3.html{{/B}}<HTML><HEAD><TITLE>ex30_3</TITLE></HEAD><BODY><appletcode="ex30_3.class"width=800height=400></applet></BODY></HTML>
进入题库练习
问答题本程序将数组arrA中元素按逆序存储在另一个相同长度的数组arrB中。 public class exam_82{ public static void main(String[] args) { int []arrA={1,3,8,4,2,6,9,0,7}; int []arrB=______; int i=0; int j=______; for(i=0;i<arrA.length;i++){ arrB[j]=arrA[i]; ______; } System.out.println("arrA:"+"arrB:"); for(i=0;i<arrA.length;i++){ System.out.println(arrA[i]+" "+arrB[i]); } } }
进入题库练习