基本操作

在考生文件夹中存有文件名为Java_1.java的文件,该程序是不完整的,请在注释行“//Found**”下一行语句的下划线地方填入正确内容,然后删除下划线,请勿删除注释行或改动其他已有语句内容。存盘时文件必须存放在考生文件夹下,不得改变原有文件的文件名。

本题的要求是:
该程序的功能是找出三个数中值的大小位于中间的数,并输出该值。程序运行结果为: median = 15

import java.io.*;

public class Java_1
{
public static void main(String args[])
{
int a=15,b=25,c=5,m;

if(a>b){
//*********Found**********
if(_____________)
m=b;
else
//*********Found**********
m=(a>c)? _____________;
}else{
if(a>c)
//*********Found**********
_____________;
else
m=(b>c)? c:b;
}
//*********Found**********
System.out.println("median = " + ______);

}
}

本题着重考察考生对Java语言判断数字大小的掌握情况。
本题中的第一个空格:在a>b时,要想m=b,则b必须大于c,因此此处空格填入"b>c";
本题中的第二个空格:在java语言中,"?:"为三目运算符,由题干意思可以看出,a>c则m=c,否则m=a,因此此处空格填入c:a;
本题中的第三个空格:由程序可知a<b,a>c,a为中间数,因此m=a,因此此处空格填入m=a;
本题中的第四个空格:程序最终要输出中间值,m存储的即为中间值,因此此处空格填入m。

本评析仅作参考。

import java.io.*;

public class Java_1
{
public static void main(String args[])
{
int a=15,b=25,c=5,m;

if(a>b){
//*********Found**********
if(b>c)
m=b;
else
//*********Found**********
m=(a>c)? c:a;
}else{
if(a>c)
//*********Found**********
m=a;
else
m=(b>c)? c:b;
}
//*********Found**********
System.out.println("median = " + m);

}
}

简单应用

在考生文件夹中存有文件名为Java_2.java的文件,该程序是不完整的,请在注释行“//Found**”下一行语句的下划线地方填入正确内容,然后删除下划线,请勿删除注释行或改动其他已有语句内容。存盘时文件必须存放在考生文件夹下,不得改变原有文件的文件名。

下面程序的功能是:给出一些学生的若干门课的成绩,计算所有成绩的中的最高分,及每个同学所有各门课的平均成绩。

程序运行结果如下:

Java二级操作题第36套_java

import java.awt.*;
import javax.swing.*;

public class Java_2{
int grades[][] = { { 77, 68, 86, 73 },
{ 96, 87, 89, 81 },
{ 70, 90, 86, 81 } };
int students, exams;
String output;
JTextArea outputArea;

public Java_2(){
students = grades.length;
exams = grades[ 0 ].length;

JFrame f = new JFrame();
f.setSize(300,300);
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//*********Found**********
outputArea = new ________________();
Container c = f.getContentPane();
//*********Found**********
c.add( ________________ );

output = "数组是:";
buildString();
output += "\n\n最高分: " + maximum() + "\n";
//*********Found**********
for ( int i = 0; i < ________________; i++ )
output += "\n第" + (i+1) + "个学生的平均分是: " +
average( grades[ i ] );
//*********Found**********
outputArea.________________( output );
}


//找最高分
public int maximum(){
int highGrade = 0;
for ( int i = 0; i < students; i++ )
for ( int j = 0; j < exams; j++ )
if ( grades[ i ][ j ] > highGrade )
//*********Found**********
highGrade = ________________;
return highGrade;
}
//对各组学生确定平均分
public int average( int setOfGrades[] ){
int total = 0;
for ( int i = 0; i < setOfGrades.length; i++ )
//*********Found**********
total += ________________;

return total /exams;
}
//输出格式
public void buildString(){
output += " ";
for ( int i = 0; i < exams; i++ )
output += "[" + i + "] ";
for ( int i = 0; i < students; i++ ) {
output += "\ngrades[" + i + "] ";
for ( int j = 0; j < exams; j++ )
output += grades[ i ][ j ] + " ";
}
}

public static void main(String[ ]args){
new Java_2();
}
}

本题着重考察考生对Java语言数组和文本框绘制的掌握情况。
本题中的第一个空格:由程序运行结果可以看出最终显示为文本区域,因此此处空格填入JTextArea;
本题中的第二个空格:容器初始化完成后要加入具体展示的内容,此处为创建好的JTextArea对象,因此此处空格填入outputArea;
本题中的第三个空格:要算出每个学生的平均分,需要以学生人数为最大值进行循环,因此此处空格填入students;
本题中的第四个空格:新建好的JTextArea对象需要设置显示的内容,使用setText方法,因此此处空格填入setText;
本题中的第五个空格:所有的成绩放在二维数组grades中,因此要对每个二维数组的值进行比较后将最大值存入highGrade,当二维数组值大于highGrade时则将该值存入,因此此处空格填入grades[i ][ j ];
本题中的第六个空格:计算平均分之前需要算好总分,要将每个学生的所有成绩相加,因此此处空格填入setOfGrades[ i ]。

本评析仅作参考。

import java.awt.*;
import javax.swing.*;

public class Java_2{
int grades[][] = { { 77, 68, 86, 73 },
{ 96, 87, 89, 81 },
{ 70, 90, 86, 81 } };
int students, exams;
String output;
JTextArea outputArea;

public Java_2(){
students = grades.length;
exams = grades[ 0 ].length;

JFrame f = new JFrame();
f.setSize(300,300);
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//*********Found**********
outputArea = new JTextArea();
Container c = f.getContentPane();
//*********Found**********
c.add( outputArea );

output = "数组是:";
buildString();
output += "\n\n最高分: " + maximum() + "\n";
//*********Found**********
for ( int i = 0; i < grades.length; i++ )
output += "\n第" + (i+1) + "个学生的平均分是: " +
average( grades[ i ] );
//*********Found**********
outputArea.setText( output );
}


//找最高分
public int maximum(){
int highGrade = 0;
for ( int i = 0; i < students; i++ )
for ( int j = 0; j < exams; j++ )
if ( grades[ i ][ j ] > highGrade )
//*********Found**********
highGrade = grades[ i ][ j ];
return highGrade;
}
//对各组学生确定平均分
public int average( int setOfGrades[] ){
int total = 0;
for ( int i = 0; i < setOfGrades.length; i++ )
//*********Found**********
total += setOfGrades[i];

return total /exams;
}
//输出格式
public void buildString(){
output += " ";
for ( int i = 0; i < exams; i++ )
output += "[" + i + "] ";
for ( int i = 0; i < students; i++ ) {
output += "\ngrades[" + i + "] ";
for ( int j = 0; j < exams; j++ )
output += grades[ i ][ j ] + " ";
}
}

public static void main(String[ ]args){
new Java_2();
}
}

综合应用

在考生文件夹中存有文件名为Java_3.java的文件,该程序是不完整的,请在注释行“//Found**”下一行语句的下划线地方填入正确内容,然后删除下划线,请勿删除注释行或改动其他已有语句内容。存盘时文件必须存放在考生文件夹下,不得改变原有文件的文件名。

程序的功能是:当正整数x,y,z的值小于某一界限值时,计算满足关系​​xx+5yy=zz​​​的元素组(x,y,z)的个数,并将满足上述关系的值最小的一组元素及总的元素个数打印出来。程序中界限值设置为100时,运行结果如下:
The first conq>onent: (1, 4,9)
Total number is: 95

import java.lang.*;
import java.util.*;

public class Java_3{

public static void main(String[ ]args){
int bound=100;
int i=0,j=0,counter=0,k=0;
int temp=0;
boolean first=true;
for(i=1;i<bound;i++){
for(j=1;j<bound;j++){
//*********Found**********
temp=___________ +5*j*j;
k=(int)Math.sqrt(temp);
//*********Found**********
if(k<bound && ___________ ){
if(first){
System.out.println("The first component: ("+i+", "+j+", "+k+")");
//*********Found**********
first=___________;
}
//*********Found**********
___________;
}
};
}
System.out.print("Total number is: "+counter);
System.exit(0);
}
}

本题着重考察考生对程序逻辑的理解情况。
本题中的第一个空格:先将关系式左边xx+5yy计算出来存入变量中,因此此处空格填入ii;
本题中的第二个空格:k经过开根号后强制转换为int,k的值有可能由于不为整数发生了变化,因此必须确保kk=temp,因此此处空格填入kk==temp;
本题中的第三个空格:由于只需要满足条件的最小一组元素,为了确保不会再打印更多满足条件的数据,必须要使first为假,因此此处空格填入false;
本题中的第四个空格:程序要求输出满足条件的总的元素个数,且程序中打印的总数使用的是counter变量,因此此处空格填入counter++。

本评析仅作参考。

import java.lang.*;
import java.util.*;

public class Java_3{

public static void main(String[ ]args){
int bound=100;
int i=0,j=0,counter=0,k=0;
int temp=0;
boolean first=true;
for(i=1;i<bound;i++){
for(j=1;j<bound;j++){
//*********Found**********
temp=i*i +5*j*j;
k=(int)Math.sqrt(temp);
//*********Found**********
if(k<bound && k*k==temp ){
if(first){
System.out.println("The first component: ("+i+", "+j+", "+k+")");
//*********Found**********
first=false;
}
//*********Found**********
counter++;
}
};
}
System.out.print("Total number is: "+counter);
System.exit(0);
}
}

箴言:因为这些东西是非常简单的。不要抱怨自己学不会,那是因为你没有足够用心。