第一套:
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(\ System.out.println(\ System.out.println(\ System.out.println(\ } }
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+\ }
}
3. public class Java_3 { int 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)的格式返回点的位置 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(\
System.out.println(\ //以(x,y)的方式打印坐标的位置 //*********Found******** //在原有位置上增加(3,4) p.translate(3,4) ____;
System.out.println(\ //打印横坐标和纵坐标的值
System.out.println(\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参加\\nJava\\n考试!\ 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; j
System.out.print(_aMatrix[i][j]_____+ \ } 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( \输入分子\ input1 = new JTextField( 10 ); c.add( input1 );
c.add(new JLabel( \输入分母和回车\ input2 = new JTextField( 10 ); c.add( input2 );
input2.addActionListener( this );
c.add( new JLabel( \计算结果\ output = new JTextField(); c.add( output );
setSize( 300, 100 ); show(); }
//处理 GUI 事件
public void actionPerformed( ActionEvent e ) {
DecimalFormat precision3 = new DecimalFormat( \ 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 } }
2. import java.awt.*;
你\\n参加\\n计算机\\n等级考试\___);