没有合适的资源?快使用搜索试试~ 我知道了~
首页二级java上机题库及答案!!考java的同学很值得一看
资源详情
资源评论
资源推荐

全国计算机等级考试二级 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********
// _________________________(""欢迎 你 参加Java 考试"");
System.out.print(""欢迎 你 参加Java 考试"");
}
}
"
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<charArray.length; 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 Java_1{
//*********Found**********
// public static ___________________ main( String args[] ){
public static void main( String args[] ){
SimpleTime t = new SimpleTime( 12, 30, 19 );
//*********Found**********
// ___________________.showMessageDialog( null, t.buildString(),
JOptionPane.showMessageDialog( null, t.buildString(),
"" \""this\"" 引用示范"",
JOptionPane.INFORMATION_MESSAGE );
System.exit( 0 );
}
}

class SimpleTime {
private int hour, minute, second;
public SimpleTime( int hour, int minute, int second ){
this.hour = hour;
this.minute = minute;
this.second = second;
}
public String buildString(){
//*********Found**********
// return ""this.toString(): "" + ___________________() +
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 );
}
}
"
5.
"import javax.swing.JOptionPane;
public class Java_1{
//*********Found**********
// public _____________________ void main( String args[] ){
public static void main( String args[] ){
PackageData d = new PackageData();
String output;
output = ""实例化后:\n"" + d.toString();
d.x = 77; //修改包访问的数据
//*********Found**********
// ______________________ = ""祝您成功!""; //修改包访问的数据
d.s = ""祝您成功!""; //修改包访问的数据
output += ""\n 修改数据后的访问结果:\n"" + d.toString();
//*********Found**********
// JOptionPane.______________________( null, output,
JOptionPane.showMessageDialog( null, output,

""对包的访问示范"",
JOptionPane.INFORMATION_MESSAGE );
System.exit( 0 );
}
}
class PackageData {
int x; //访问包的实例变量
String s; //访问包的实例变量
//构造方法
public PackageData(){
x = 0;
s = ""Hello"";
}
public String toString(){
return ""x: "" + x + "" s: "" + s;
}
}
"
6.
"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 ); // 结束程序
}
}
/* JOptionPane 类的常用静态方法如下:
showInputDialog()
showConfirmDialog()
showMessageDialog()
showOptionDialog()
*/"
7.
"//Interest.java
//计算复杂利息
import java.text.DecimalFormat;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;

public class Java_1{
public static void main( String args[] ){
double amount, principal = 1000.0, rate = .05;
DecimalFormat precisionTwo = new DecimalFormat( ""0.00"" );
//*********Found**********
// JTextArea outputTextArea = new ____________________( 11, 20 );
JTextArea outputTextArea = new JTextArea( 11, 20 );
outputTextArea.append( ""年\t 存款总计\n"" );
for ( int year = 1; year <= 10; year++ ) {
amount = principal * Math.pow( 1.0 + rate, year );
outputTextArea.append( year + ""\t"" +
//*********Found**********
// precisionTwo.___________________( amount ) + ""\n"" );
precisionTwo.format( amount ) + ""\n"" );
}
//*********Found**********
// JOptionPane._____________________(
JOptionPane.showMessageDialog(
null, outputTextArea, ""复合利息"",
JOptionPane.INFORMATION_MESSAGE );
System.exit( 0 );
}
}
"
8.
"//分析球队升级程序
import javax.swing.JOptionPane;
public class Java_1 {
public static void main( String args[] )
{
//初始化变量
int passes = 0, //考试及格的队员数
failures = 0, //考试不及格的队员数
student = 1, //学生计数器
result; //分析结果
String input, //输入值
output; //输出字符串
//10 个队员,用计数器控制循环
while ( student <= 10 ) {
input = JOptionPane.showInputDialog(
""输入队员考核结果 (1=及格,2=不及格)"" );
//*********Found********
剩余63页未读,继续阅读
安全验证
文档复制为VIP权益,开通VIP直接复制

评论0