ImageVerifierCode 换一换
格式:DOCX , 页数:31 ,大小:282.92KB ,
资源ID:3990169      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/3990169.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(Java程序填空.docx)为本站会员(b****4)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

Java程序填空.docx

1、Java程序填空本题的功能是计算二维数组arr=34,21,45,67,20),23,10,3,45,76,22,3,79,56,50中的最小值,并输出。参考答案:第1处:j5或j4第2处:j0第3处:i或i1或ii1本题的功能是通过鼠标确定两个点,然后画两点间的直线。窗口中有个按钮“Draw line”,单击该按钮后,它就处于按下状态,然后用鼠标在窗口中单击下,在单击的地方就会出现个坐标圆点,用鼠标在另外个地方单击下又会出现另外个圆点,并且此时在两个坐标圆点间画出条直线,且“Draw line”处于可用状态,再单击这个按钮就可以画另外条直线。 参考答案:第1处:Point第2处:mevtge

2、tPoint下面的程序中,有两个文本框,Input和Output,用户在Input文本框中输入字符串后回车,字符串会在Output文本框中出现。 参考答案:第1处;new Actionlistener()第2处:tflgetText()本题中定义了长度为20的维整型数组a,并将数组元素的下标值赋给数组元素,最后打印输出数组中下标为奇数的元素。public class javalpublic static void main(Stringargs)int a=Int i:forai=ifori+)=1:i=0;i20;i+)Systemoutprint(”a”+i+”=”+ai+”,“); 参考

3、答案:第1处:new int020第2处:i0;i20第3处:i%2 !0本题的功能是计算二维数组arr=34,21,45,67,20,23,10,3,45,76,22,3,79,56,50中的最小值,并输出。public class javalpublic static void main(Stringargs)int arr=34,21,45,67,20),23,10,3,45,76,22,3,79,56,50;int i=0:intj=0;int min=arr00;while(i3)while( )if(arrijmin)min=arrij;j+; ; ;Systemoutprintl

4、n(The min:+min); 参考答案:第1处:j5或j=O)SystemOUtprint(arrn+); 参考答案:第1处:int n第2处:arr1ength-1第3处:n-或n=n-1或n-=l.本题定义了一个方法add(),用于求两个整形数的和。方法中有两个整形参数a和b,方法体中计算a和b的和sum,并将结果返回。程序中调用add()方法求整数24和34的和,并将结果打印输出。public class javalpublic static void main(Stringargs)int a=24,b=34;Systemoutprintln(add(a,b);public sta

5、tic int add( );suma+b; 参考答案:第1处:int a,int b第2处:int sum第3处:return sum本题将一个整形变量opl的二进制的低3位全部变成1。public class javalpublic static void main(Stringargs)opl=21;int op2=7:res;Systemoutprintln(res); 参考答案:第1处:int第2处:int第3处:res=oplop2本题的功能是计算l10之间除了5以外的各个自然数的和。public class javalpublic static void main(Stringa

6、rgs)int i=1 ;int sum=0;while(i=10)if(i= =5);i+;Systemoutprintln(sum=+sum); 参考答案:第1处:i=i+1或i+或i+=1第2处:continue第3处:sum+=i或sum=sum+i本题的功能是获取鼠标在窗口中的位置。当鼠标移进窗口中,就会实时显示鼠标在窗口中的相对位置,比如显示为鼠标的当前位置:X:Y(其中,X为横坐标,Y为纵坐标)。import javaawt*;import javaawtevent*;import javautil*;import javaxswing*;public class java2pu

7、blic static void main(Stringargs)MouseFrame frame=new MouseFrame();framesetDefaultCloseoperation(JFrameEXIT_0N CLOSE);frameshow();class MouseFrame extends JFramepublic MouseFrame()setTitle(java2);setSize(WIDTH,HEIGHT);MousePanel panel=new MousePanel();Container contentPane=getContentPane();contentPa

8、neadd(panel);public static final int WIDTH = 300;public static final int HEIGHT=200;class MousePanel extends JPanelpublic MousePanel()addMouseListener(new MouseHandler();addMouseMotionListener(new MouseMotionHan-dler();public void paintComponent(Graphics g)(superpaintComponent(g);String text=鼠标指针位置:

9、+mousex+:+mousey;gdrawString(text,10,10);private int mousex,mousey;private class MouseMotionHandlerpublic void mouseMoved(MouseEvent event)mousex=eventgetX();mousey=eventgetY();repaint();public void mouseDragged(MouseEvent event)mousex=eventgetX();mousey=eventgetY();repaint();private class MouseHand

10、lerpublic void mousePressed(MouseEvent eveat)mousex=eventgetX();mousey=eventgetY(); 参考答案:第1处:implements MouseMotionListener第2处:extends MouseAdapter本题主窗口中包括一个文本框和一个文本域,在上面的文本框中输入一个整数并按回车键,就会在下面的文本域中显示该整数的平方值;如果在文本框中输入的不是一个整数,将弹出一个警告窗口。tmport javaawtevent*:import javaawt*;import javaxswingJOptionPane;

11、class Dwindow extends Frame implements ActionLis-tenerTextField inputNumber;TextArea show;Dwindow(String s)super(s):inputNumber=new TextField(22);inputNumberaddActionListener(this);show=new TextArea();add(inputNumber,BorderLayoutNORTH);add(show,BorderLayoutCENTER);setBounds(60,60,300,300);setVisible

12、(true);validate();addWindowListener(new WindowAdapter()public void windowClosing(WindowEvent e)Systemexit(0););public void actionPerformed(ActionEvent e)boolean boo=false;if(egetSource()= =inputNumber)String s=;char a=StoCharArray();for(int i=0;ialength;i+)if(!(CharacterisDigit(ai)boo=true;if(boo= =

13、true)JOptionPaneshowMessageDialog(this,您输入了非法字符,警告对话框,);inputNumbersetText(null);else if(boo= =false)int number=IntegerparseInt(s);showappend(n+number+平方:+(num-bet*number):public class java2public static void main(String args) new Dwindow(java2); 参考答案:第1处:inputNumbergetText()第2处:JOptionPaneWARNING_M

14、ESSAGE本题是一个Applet,它的功能是在窗口上添加1212个标签,并且横向和纵向标签的颜色为黑白相间。import javaapplet*;import javaawt*;import java,awtevent*;pubhc class java2extends AppletGridLayout grid;pubhc void init()grid=new GridLayout(12,12);setLayout(grid);Label=new Label1212;for(int i=0;i12;i+)for(int j=0;j12;j+)labelij=;if(i+j)2= =0)l

15、abelijsetBackground(Colorblack);elselabelijsetBackground(colorwhite);add(labelij); 参考答案:第1处:label第2处:new label()本题中定义了一个树型的通信录,窗El左侧是一个树,右侧是一个文本域,单击树的结点,则在右侧文本域中显示相关信息,如果单击的是树结点,则显示对应名字的信息。import javaxswing*;import javaxswingtree*;import javaawt*;import javaawtevent*;import javaxswingevent*;class My

16、tree2 extends JFrameJTree tree=null;JTextArea text=new JTextArea(20,20);Mytree2()Container con=getContentPane();DefauhMutableTreeNode root=new Default-MutableTreeNode(同学通信录);DefaultMutableTreeNode tl=new Default-MutableTreeNode(大学同学);DefaultMutableTreeNode t2=new Default-MutableTreeNode(研究生同学);Defau

17、ltMutableTreeNode tll=new Default-MutatleTreeNode(艳);DefaultMutableTreeNode tl2=new Default-MutableTreeNode(小永);DefaultMutableTreeNode t21=new Defauh-MutableTreeNode(王小小);DefauhMutableTreeNode t22=new Defauh-MutableTreeNode(董小);setTitle(java2);rootadd(t1);rootadd(t2);tladd(t1_1);tladd(t1_2);t2add(t2

18、_1);t2add(t2_2);tree=new JTree(root);JSerollPane scrollpane=new JScrollPane(text);JSplitPane splitpane=new JSplitPane(JSplitPaneHORIZONTAL SPLIT,true,tree,scrollpane);treeaddTreeSeleetionListener(this);conadd(splitpane);addWindowListener(new WindowAdapter() public void windowClosing(WindowEvent e)Sy

19、stemexit(0););setVisible(true);setBounds(70,80,200,300);public void valueChanged(TreeSelectionEvent e)if(egetSouree()= =tree)DefauhMutableTreeNode node=(DefaultMutableTreeNode)treegetLastSelected-PathComponent();if(nodeisLeaf()(String str=;if(strequals(艳)(textsetText(str+:联系:0411-4209876);else if(st

20、requals(小永)textsetText(str+:联系:010-62789876);else if(strequals(王小小)textsetText(str+:联系:0430-63596677);)else if(strequals(董小)textsetText(str+:联系:020-85192789);elsetextsetText(nodegetUserObject()toString();public class java2public static void main(String args)Mytree2 win=new Mytree2();winpack(); 参考答案:

21、第1处:implements TreeSelectionListener第2处:nodetoString()本题中,主窗口有一个按钮“打开对话框”和一个文本域,单击按钮“打开对话框”后会弹出一个对话框,对话框上有两个按钮“Yes和“N0”,单击对话框上的“Yes”和“N0”按 钮后返回主窗口,并在右侧文本域中显示刚才所单击的按钮信息。import javaawtevent*;import javaawt*;class MyDialogimplements ActionListenerstatic final int YES=1,N0=0;int message=-1;Button yes,no

22、;MyDialog(Frame fString S,boolean b)super(f,S,b);ves=new Button(Yes);yesaddActionListener(this);no=new Button(No);noaddActionListener(this)osetLayout(new FlowLayout();add(yes);add(no);setBounds(60,60,100,100);addWindowListener(new WindowAdapter() public void windowClosing(WindowEvent e)message=-1;se

23、tVisible(false););public void actionPerformed(ActionEvent e)if(egetSource()= =yes)message=YES;setVisible(false);else if(egetSource()= = no)message=NO;setVisible(false);public int getMessage()return message;class Dwindow extends Frame implements ActionLis-tenerTextArea text;Button button;MyDialog dia

24、log;Dwindow(String s)super(s);text=new TextArea(5,22);button=new Button(打开对话框);buttonaddActionListener(this);setLayout(new FlowLayout();add(button);add(text);dialog=new MyDialog(this,Dialog,true);setBounds(60,60,300,300);setVisible(true);validate();addWindowListener(new WindowAdapter()public void wi

25、ndowClosing(WindowEvent e)Systemexit(0););public void actionPerformed(ActionEvent e)if(egetSource()= =button);if(dialoggetMessage()= =MyDialogYES)textappend(n你单击了对话框的yes按钮);else if(dialoggetMessage()= =MyDialogNO)textappend(n你单击了对话框的N0按钮);public class java2public static void main(String args)new Dwi

26、ndow(java2); 参考答案:第1处:extends Dialog第2处:dialogsetVisible(true)题中,在下画线上填写代码,指定变量b为字节型,变量f为单精度实型,变量1为64位整型。public class javalpublic static void main(String-args)b=49;f=89f;l=0xfedl;Systemoutprintln(b=+b);Systemoutprintln(f=+f):SystemOUtprintln(l=+1); 参考答案:第1处:byte第2处:float第3处:long本题的功能是读人运行程序时所传入的参数(一个或多个),并将参数依次显示出来,比如运行程序:java javalpartl part2,则打印输出为:partl part2。public class javalpublic static void main(Stringargs)int i=0:w

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1