全国计算机等级考试二级Java捷成模拟上机试题
全部是程序填空题,需要填空的语句用”//”注释了,答案就是该语句后面的语句
1.
"//计算两个整数的乘法
import javax.swing.JOptionPane;
public class Java_1 {
public static void main( String args[] ) {
int x, y, result;
String xVal, yVal;
xVal = JOptionPane.showInputDialog( ""输入第1个整数:"" );
yVal = JOptionPane.showInputDialog( ""输入第2个整数:"" );
//*********Found********
// x = Integer.parseInt( _____________ );
x = Integer.parseInt( xVal );
y = Integer.parseInt( yVal );
result = x * y;
//*********Found********
// JOptionPane._________________________( null, ""两个数的积: "" + result );
JOptionPane.showMessageDialog( null, ""两个数的积: "" + result );
System.exit( 0 );
}
}
"
2.
"//用一个打印语句输出多行结果
public class Java_1
{
public static void main( String args[] )
{
//*********Found********
// _________________________(""欢迎\n你\n参加\nJava\n考试"");
System.out.print(""欢迎\n你\n参加\nJava\n考试"");
}
}
"
3.
"import java.io.*;
public class Java_1 {
public static void main(String[] args) {
char[] charArray = {'a','b','c','d','e','f','g','h','i'};
char c ;
try{
//*********Found**********
// DataOutputStream out = new ______________________(
DataOutputStream out = new DataOutputStream(
new FileOutputStream(""test.dat""));
for(int i =0; i
out.writeChar(charArray[i]);
}
out.close();
DataInputStream in = new DataInputStream(
//*********Found**********
// new FileInputStream(""____________________""));
new FileInputStream(""test.dat""));
while(in.available() != 0){
c=in.readChar();
System.out.print(c+"" "");
}
System.out.println();
//*********Found**********
// in.____________________();
in.close();
}catch(IOException e){}
}
}
"
4.
"import javax.swing.*;
import java.text.DecimalFormat;
public class