[计算机类试卷]国家二级(JAVA)机试模拟试卷66及答案与解析.doc
《[计算机类试卷]国家二级(JAVA)机试模拟试卷66及答案与解析.doc》由会员分享,可在线阅读,更多相关《[计算机类试卷]国家二级(JAVA)机试模拟试卷66及答案与解析.doc(7页珍藏版)》请在麦多课文档分享上搜索。
1、国家二级( JAVA)机试模拟试卷 66及答案与解析 一、基本操作题( 30分) 1 下列程序中,要求按照从小到大的顺序输出 1 100之间所有能被 7整除的数字,请将下列程序补充完整。 注意:请勿改动 main()主方法和其他已有语句内容,仅在横线处填入适当语句。 public class Example1_3 public static void main(String argv) int i = 1; _ if(_) System.out.print(i+ “,“); _ while(i 100); System.out.println(); 二、简单应用题( 40分) 2 请完成下面的
2、程序:实现一个可以每秒跳动的时钟。运行如下图所示。请填写横线处的内容。 注意:请勿改动 main主方法和其他 已有语句内容,仅在下划线处填入适当的语句。 import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.util.*; public class Example2_12 extends JFrame (1) implements Runnable Thread thread1; Color handColor; Color numberColor; JLabel jlabell = new
3、JLabel(); public Example2_12() enableEvents(AWTEvent.WINDOW_EVENT_MASK); try getContentPane().add(jlabell, BorderLayout. SOUTH); catch (Exception e) System.out.println(e.getMessage(); public static void main(String args) Example2 12_clock1 = new Example2_12(); clock1.init(); clock1.start(); clock1.s
4、etSize(260, 230); clock1.setResizable(false); clock1.show(); public void init() int x, y; handColor = Color.blue; numberColor = Color.darkGray; setBackground(Color.white); public void paint (Graphics g) int xh, yh, xm, ym, xs, ys, s = 0, m = 10, h = 10, xpoint, ypoint; String today; Calendar c1 = _;
5、 s = c1.get(Calendar.SECOND); m = c1.get(Calendar.MINUTE); h = c1.get(Calendar.HOUR); int day, month, year, weekday; day = c1.get(Calendar.DATE); month = c1.get(Calendar.MONTH) + 1; year = c1. get (Calendar. YEAR); weekday = c1.get (Calendar. DAY_OF_WEEK); jlabell.setText(“Today is “+ year + “/“ + m
6、onth + “/“ + day + “/ “+ “Time:“ + h + “:“ + m + “:“ + s); xpoint = 130; ypoint = 100; xs =(int) (Math.cos(s * 3.14f / 30 - 3.14f / 2) * 45 + xpoint); ys =(int) (Math.sin(s * 3.14f / 30 - 3.14f / 2) * 45 + ypoint); xm =(int) (Math.cos (m * 3.14f / 30 - 3.14f / 2) * 40 + xpoint); ym =(int) (Math.sin(
7、m * 3.14f / 30 - 3.14f / 2) * 40 + ypoint); xh =(int) (Math.cos( (h * 30 + m / 2) * 3.14f / 180 - 3.14f / 2) * 30 + xpoint); yh =(int) (Math.sin( (h * 30 + m / 2) * 3.14f / 180 - 3.14f / 2) * 30 + ypoint); g.setColor (handColor); g.clearRect(0, 0, 260, 200); g.drawOval(xpoint / 2 + 10, ypoint / 2 -
8、5, 110, 110); g.setColor(numberColor); g.drawString(“9“, xpoint - 45, ypoint + 3); g.drawString(“3“, xpoint + 40, ypoint + 3); g.drawString(“12“, xpoint - 5, ypoint - 37); g.drawString(“6“, xpoint - 3, ypoint + 45); g.setColor(getBackground ( ) ); g.setColor(numberColor); g.drawString(“ “, 5, 125);
9、g.drawLine(xpoint, ypoint, xs, ys); g.setColor(handColor); g.drawLine(xpoint, ypoint, xm, ym); g.drawLine(xpoint, ypoint, xh, xh); public void start() thread1 = new Thread(this); thread1. _; public void stop () thread1=null; public void update (Graphics g) paint (g); public void run () Thread me = T
10、hread. currentThread (); while (thread1 = me) try Thread. currentThread ( ) . sleep ( 100 ); catch (InterruptedException e) e.printStackTrace(); repaint ( ); protected void processWindowEvent(WindowEvent e) super.processWindowEvent(e); if (e.getID() = WindowEvent.WINDOW_CLOSING) System.exit(0); 三、综合
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
2000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 试卷 国家 二级 JAVA 模拟 66 答案 解析 DOC
