




已阅读5页,还剩28页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
第一套:1. import java.io.*;public class Java_1 public static void main(String args) char a=r; byte b=8; int i=55; /*Found* long_ n=1024L; float f=103.7f; /*Found* double_ d=954.2431; int a1=a+i; long n1=n-a1; float f1=b*f; double d1=f1/a1+d; System.out.println(a1=+a1); System.out.println(n1=+n1); System.out.println(f1=+f1); System.out.println(d1=+d1); 2. import java.util.Random;public class Java_2 public static void main(String args)Random random = new Random();float p = random.nextFloat();/产生0.0与1.0之间的一个浮点数int n = Math.round(10*p); /构造10以内的一个整数long f = 1 ; /保存阶乘的结果int i = 1 ; /循环变量 /*Found* do _f*=i_; i+; /*Found* _while(i=n); _ System.out.println(n+!= +f); 3. public class Java_3int x,y; /点的坐标public Java_3() /无参数的构造方法 /*Found* /带两个参数的构造方法 public Java_3(int x,int y)_ this.x=x;this.y=y;_ /*Found* /带一个参数的构造方法 public Java_3(Java_3 p) x=p.x;y=p.y;_ public Java_3 getLocation() /以对象的形式返回当前点的位置 /*Found* /实例化一个Java_3对象p Java_3 p=new Java_3(x,y) _; /*Found* /返回对象p _return p_; public int getX()return x; /返回点的横坐标public int getY()return y; /返回点的纵坐标public void move(int x,int y)this.x = x;this.y = y; /把当前点移到新的位置(x,y)上public String toString()return (+x+,+y+); /以(x,y)的格式返回点的位置public void translate(int x,int y)this.x += x;this.y += y; /在原有坐标上分别增加x和y/主方法public static void main(String args) /*Found* /生成一个对象(5,5) Java_3 p=_new Java_3(5,5)_; System.out.println(x=+ p.x+ y=+ p.y); System.out.println(Location is+ p.toString(); /以(x,y)的方式打印坐标的位置 /*Found* /在原有位置上增加(3,4) p.translate(3,4) _; System.out.println(x=+ p.x+ y=+ p.y); /打印横坐标和纵坐标的值 System.out.println(Location is+ p.toString(); /以(x,y)的方式打印坐标的位置第二套:1. import javax.swing.JOptionPane; /导入JOptionPane类public class Java_1 public static void main( String args ) /*Found* JOptionPane._ showMessageDialog_( null, 欢迎n你n参加nJavan考试! ); System.exit( 0 ); / terminate the program 2. public class Java_2 public static void main(String args) int aMatrix = 1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5;int i = 0; /循环变量int j = 0; /循环变量 /print matrix for(i = 0; i aMatrix.length; i+) /*Found* for ( j = 0; jaMatrixi.length_; j+) /*Found* System.out.print(_aMatrixij_+ ); System.out.println(); 3. import java.awt.event.*;import java.awt.*;import javax.swing.*;import java.text.*;/*Found*public class Java_3 extends JFrame_ implements ActionListener private JTextField input1, input2, output; private int number1, number2; private double result; / 初始化 public Java_3() /*Found* super_( 示范异常 ); Container c = getContentPane(); c.setLayout( new GridLayout( 3, 2 ) ); c.add( new JLabel( 输入分子,SwingConstants.RIGHT ) ); input1 = new JTextField( 10 ); c.add( input1 ); c.add(new JLabel( 输入分母和回车,SwingConstants.RIGHT ) ); input2 = new JTextField( 10 ); c.add( input2 ); input2.addActionListener( this ); c.add( new JLabel( 计算结果, SwingConstants.RIGHT ) ); output = new JTextField(); c.add( output ); setSize( 300, 100 ); show(); /处理 GUI 事件 public void actionPerformed( ActionEvent e ) DecimalFormat precision3 = new DecimalFormat( 0.000 ); output.setText( ); /空的JTextField输出 try number1 = Integer.parseInt( input1.getText() ); number2 = Integer.parseInt( input2.getText() ); result = quotient( number1, number2 ); /*Found* _ output.setText(precision3.format(result)_; catch ( NumberFormatException nfe ) /*Found* _JOptionPane.showMessageDialog_( this, 你必须输入两个整数, 非法数字格式, JOptionPane.ERROR_MESSAGE ); catch ( Exception dbze ) /*Found* _JOptionPane.showMessageDialog_( this, 除法异常, 除数为零, JOptionPane.ERROR_MESSAGE ); / 定义求商的方法,如遇除数为零时,能抛出异常。 public double quotient( int numerator, int denominator )throws Exception if ( denominator = 0 )throw new Exception(); return ( double ) numerator / denominator; public static void main( String args ) Java_3 app = new Java_3(); app.addWindowListener( new WindowAdapter() public void windowClosing( WindowEvent e ) e.getWindow().dispose(); System.exit( 0 ); ); 第三套:1. /用一个打印语句输出多行结果public class Java_1 public static void main( String args ) /*Found* System.out.println(_欢迎n你n参加n计算机n等级考试_); 2. import java.awt.*;import java.awt.event.*;public class Java_2 extends Frame public Java_2(String s)super(s);public static void main(String args) Java_2 fr = new Java_2(Testing); Button b=new Button(Please press me!); /*Found* b.addActionListener(_new HandleButton()_); fr.add(b); fr.pack(); /*Found* fr.addWindowListener(new _WindowAdapter_()public void windowClosing(WindowEvent e) System.exit(0); ); fr.setVisible(true);class HandleButton implements ActionListener public void actionPerformed(ActionEvent e)System.out.println(The button is pressed!); 3. /*Found*import javax.swing_.*;public class Java_3 public static void main( String args ) String s1, s2, s3, s4, output;/声明5个字符串引用 /初始化字符串 s1 = new String( 您好! ); s2 = new String( 您好! ); / 判别字符串相同否 if (s1 = s2 ) output = s1 和 s2 是内存中同一个对象; else output = s1 和 s2 不是内存中同一个对象; /判别字符串内容相等否 /*Found* if (s1.equals(s2)_ ) output += ns1 和 s2内容相等; else output += ns1 和s2 内容不相等are not equal; / 用intern()方法来获得与对象s1,s2内容都是您好!字符串的引用s3 和 s4 /*Found* s3 = s1_.intern()_; /*Found* s4 = s2_.intern()_; /判别s3和s4是否是内存中相同的对象 if ( s3 = s4 ) output += ns3 和s4 是内存中同一个对象; else output += ns3 和 s4 不是内存中同一个对象; /判别s1和s3是否引用同一个对象 if ( s1 = s3 ) output += ns1和s3是内存中同一个对象; else output += ns1和s3不是内存中同一个对象; / 判别s2和s4是否是内存中相同的对象 if ( s2 = s4 ) output += ns2和s4是内存中同一个对象; else output += ns2和s4不是内存中同一个对象; /判别s1和s4是否是内存中同一个对象 if ( s1 = s4 ) output += ns1和s4是内存中同一个对象; else output += ns1和s4不是内存中同一个对象; JOptionPane.showMessageDialog( null, output, /*Found* _示范String的intern()方法_, JOptionPane.INFORMATION_MESSAGE ); System.exit( 0 ); 第四套:1import javax.swing.JApplet; / import class JAppletimport java.awt.Graphics; / import class Graphicspublic class Java_1 extends JApplet /*Found* public void paint( _Graphics_ g ) g.drawString( 欢迎你参加Java考试!, 25, 25 ); 2. import java.io.*;public class Java_2 public static void main(String args) throws IOException File inputFile; File outputFile; FileInputStream in; FileOutputStream out; int c; inputFile = new File(source.txt); outputFile = new File(dest.txt); in = new FileInputStream(inputFile); /*Found* _out = new FileOutputStream_(outputFile); while (c = in.read() != -1) /*Found* _ out.write(c)_; in.close(); out.close(); 3. import javax.swing.JOptionPane;public class Java_3 public static void main( String args ) String firstNumber, / 用户输入第1个字符串 secondNumber, / 用户输入第2个字符串 result; / a string containing the output int number1, / 比较的第1个数 number2; / 比较的第2个数 /读用户输入的第1个字符串 read first number from user as a string firstNumber = JOptionPane.showInputDialog( Enter first integer: ); /读用户输入的第2个字符串read second number from user as a string secondNumber = JOptionPane.showInputDialog( Enter second integer: ); / 将字符串类型转换成整数类型 number1 = Integer.parseInt( firstNumber ); number2 = Integer.parseInt( secondNumber ); result = ; /*Found* if ( number1 = number2 ) result = number1 + = + number2; if ( number1 != number2 ) result = number1 + != + number2; if ( number1 number2 ) result = result + n + number1 + number2 ) result = result + n + number1 + + number2; if ( number1 = number2 ) result = result + n + number1 + = number2 ) result = result + n + number1 + = + number2; /显示结果 /*Found* _JOptionPane.showMessageDialog_( null, result, 比较结果 , /*Found* _JOptionPane._INFORMATION_MESSAGE ); /程序正常退出 /*Found* _ System.exit(0)_; 第五套: 1. import javax.swing.JApplet;import java.awt.Graphics;/*Found*public class Java_1 extends _JApplet_ public void paint( Graphics g ) g.drawString( 欢迎你来参加, 25, 25 ); g.drawString( Java 语言考试!, 25, 40 ); 2. import java.awt.* ;import java.applet.* ;public class Java_2 extends Applet String s; public void init() /*Found* s = getParameter(_strings_); public void paint(Graphics g)g.drawString(s,20,20); 3. import javax.swing.*; /*Found*import _ java.text_.*;public class Java_3 public static void main( String args ) /*Found* SimpleTime t = new _ SimpleTime_ ( 12, 30, 19 ); /*Found* _ JOptionPane.showMessageDialog_( null, t.buildString(), Demonstrating the this Reference, /*Found* _JOptionPane_.INFORMATION_MESSAGE ); System.exit( 0 ); class SimpleTime private int hour, minute, second; public SimpleTime( int hour, int minute, int second ) this.hour = hour; /*Found* _this.minute_ = minute; this.second = second; public String buildString() /*Found* return this.toString(): +_this.toString()_ + ntoString(): + toString() + nthis (with implicit toString() call): + this; public String toString() DecimalFormat twoDigits = new DecimalFormat( 00 ); return twoDigits.format( this.hour ) + : + twoDigits.format( this.minute ) + : + twoDigits.format( this.second ); 第六套:1public class Java_1 public static void main(String args) final char chrA=A; char chrDisplay; /*Found* for(int i=0;ib) t=a; a=b; _b=t_; if(ac) t=a; a=c; c=t; /*Found* if(_bc_) t=b; b=c; c=t; System.out.println(a=+a+,b=+b+,c=+c); 2. import java.util.*;import java.io.*;public class Java_2 public static void main(String args) int a,b,c; Random r=new Random(); for(int i=0;i3200;i+) try /*Found* a=r._ nextInt_() ; /得到一个随机数 /*Found* b=r._ nextInt_() ; /得到一个随机数 c=a/b; /*Found* _ catch_(Exception e) System.out.println(不能被零除!) ; c=0; System.out.println(结果为:+c) ; 3. import javax.swing.*;import java.awt.event.*;import java.awt.*;public class Java_3 private static JLabel lbl; private static JTextArea txt; public static void main(String args) JFrame frame=new JFrame(全国计算机等级考试); lbl=new JLabel(); txt=new JTextArea(); frame.getContentPane().add(txt,BorderLayout.CENTER ); frame.getContentPane().add(lbl,BorderLayout.SOUTH ) ; /*Found* frame._ addWindowListener_(new WindowHandler() ;/注册监听器WindowHandler /*Found* txt.addMouseMotionListener(new _() public void mouseMoved(MouseEvent e) String strTemp; strTemp=当前鼠标位置:(+e.getX() +,+e.getY() +); /*Found* lbl._ setText_(strTemp);/显示出鼠标位置 ) ; frame.setSize(200,150) ; frame.show() ; class WindowHandler implements WindowListener public void windowOpened(WindowEvent e) public void windowClosing(WindowEvent e) System.exit(0) ; public void windowClosed(WindowEvent e) public void windowIconified(WindowEvent e) public void windowDeiconified(WindowEvent e) public void windowActivated(WindowEvent e) public void windowDeactivated(WindowEvent e) 第八套:1. import javax.swing.*;import java.awt.event.*;import java.awt.*;public class Java_1 public static void main(String args) JFrame frame=new JFrame(全国计算机等级考试); JButton btnExit=new JButton(退出(X); btnExit.setMnemonic(KeyEvent.VK_X ) ; btnExit.addActio
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 魅力女性的课件
- 济南市2024-2025学年八年级上学期语文月考测试试卷
- 高速路安全知识培训心得
- 高速业务知识培训课件要求
- 医院保洁、中央运输服务方案
- 高血压基本知识培训总结课件
- 建设项目可行性研究技术服务合同
- 抽水蓄能电站移民安置监理评估合同
- 电脑培训知识付费平台课件
- 电脑主机知识培训课件
- 股权代持协议英文版10篇
- 酒吧消防火灾应急预案(3篇)
- 国企物业面试题目及答案
- 2024年会计法规综合考查试题及答案
- 鉴定机构运营管理制度
- 医院不良事件上报制度
- 双馈风机送出线路的暂态响应特性及保护适应性分析
- 2025年江苏东台市国有资产经营有限公司招聘笔试参考题库含答案解析
- 信息技术(基础模块)课件 第5章-新一代信息技术概述
- “教联体”在家校社协同育人中的实践
- 商业装修工程合同样本范本
评论
0/150
提交评论