阅读以下程序说明和java代码,将应填入(n)处的字句写在对应栏内。
[说明]
本程序接收输入的学生信息,包括学号、姓名、成绩,原样输出信息并计算学生的平均成绩。其中学生类Stud除了包括no(学号)、name(姓名)和grade(成绩)数据成员外,还有两个静态变量 sum和num,分别存放总分和人数,另有一个构造函数、一个普通成员函数disp()和一个静态成员函数avg()用于计算平均分。
[Java代码]
public class Stud {
public int no;
public String name;
public double grade;
public (1) double sum=0;
public static int num=0;
public Stud(int no,String name,double grade) {
this.no = no;
this.name = name;
this.grade = grade;
this.sum=(2);
(3);
}
public static double avg(){
return (4);
}
public void disp(){
System.out.println(this.no+"\t"+this.name+"\t"+this.grade);
}
public static void main(String[] args) {
Stud []students = {new Stud (1,"Li", 81), new Stud(2,"Zhao",84.5), new Stud(3,"Zhang", 87)};
System.out.pfintln("no\tname\tgrade");
students[0].disp();
students[1].disp();
students[2].disp();
System.out.println("avg="+(5));
}
}
第1题:
阅读以下说明和JAVA 2代码,将应填入(n)处的字句写在对应栏内。
[说明]
以下程序为类类型的变量应用实例,通过异常处理检验了类CCircle的变量的合法性,即参数半径应为非负值。仔细阅读代码和相关注释,将程序补充完整。
[JAVA代码]
//定义自己的异常类
class CCircleException extends Exception
{
}
// 定义类 CCircle
class CCircle
{
private double radius;
public void setRadius ( double r ) (1)
{
if ( r<0 ) {
(2)
}
else
(3)
}
Public void show ( ) {
System. out. println ( "area="+3.14*radius*radius );
}
}
public class ciusample
{
public static void main ( String args[] )
{
CCircle cir=new CCircle( );
(4) {
cir. setRadius ( -2.0 )
}
(5)
{
System. out. println ( e+" throwed" ) ;
}
cir. show( ) ;
}
}
第2题:
●试题二
阅读下列函数说明和C代码,将应填入(n)处的字句写在答题纸的对应栏内。
【说明】
该程序运行后,输出下面的数字金字塔
【程序】
include<stdio.h>
main ()
{char max,next;
int i;
for(max=′1′;max<=′9′;max++)
{for(i=1;i<=20- (1) ;++i)
printf(" ");
for(next= (2) ;next<= (3) ;next++)
printf("%c",next);
for(next= (4) ;next>= (5) ;next--)
printf("%c",next);
printf("\n");
}
}
第3题:
第4题:
阅读下列程序说明和C程序,将应填入(n)处的字句写在对应栏内。
[函数2.1说明]
下面程序的功能是计算x和y的最小公倍数。
[函数2.1]
main()
{ int m,n,d,r;
seanf("%d %d",&m,&n);
if(m<n) {r=m;m=n;n=r;}
(1);
while (d%n! =0) (2);
printf("%d\n",d);
}
[函数2.2说明]
下述程序接收键盘输入,直到句点“.”时结束。输入的字符被原样输出,但连续的空格输入将转换成一个空格。
[函数2.2]
include <stdio.h>
main()
{ char c,preChar='\0';
c = getchar();
while(c! = '.'){
if((3)) putchar(c);
else if(preChar! =' ') putchar(c);
(4);
c=(5);
}
}
第5题:
试题三(共 15 分)
阅读以下说明和 C 程序,将应填入 (n) 处的字句写在答题纸的对应栏内。