文档介绍:一、程序填空题(每空
3 分,共 30 分)
以下程序要求从键盘输入一个整数,判别该整数为几位数,并输出结果,请将下面的程序填写完整。
public
class Blank1 {
public static void main(String[]
Scanner sc =new Scanner(
int count =0, t ;
int x =sc .nextInt();
sc .close();
t =x ;
while ( t !=0){
count ++;
args ) throws
(1) );
IOException {
( 2 )
;
}
System.
out .println(
x +"
是 " +count +" 位数。 " );
}
}
答案:( 1) System. in
2) t =t /10
在下面的程序中使用方法重载分别实现了两个和三个整数的相加,请将下面的程序填写完整。 class AddOver{
public
return
a +b ;
(3 )
{
}
public int
add( int
a,
int
b,
int
c ){
return
a +b +c ;
}
}
public
class Blank2{
public static void main(String[]
AddOver a= (4 ) ;
System. out .println( a .add(1,2));
System. out .println( a .add(1,2,3));
args ){
}
}
答案:( 3) int add( int a , int b )
4)new AddOver()
3. 构造一个类来描述一个点,该类的构成包括点的 x 和 y 两个坐标,以及一些对点进行的操作,包括:
取得点的坐标值,利用另一个点对当前点的坐标进行赋值,请将下面的程序填写完整。
class
Point{
int
x , y ;
public
( 5 )
(
int
x , int
y ){
this
. x =x ;
this
. y =y ;
}
public Point getPoint(){
Point temp = new Point(0,0);
temp . x =x ; temp . y =y ;
return (6) ;
}
public
void setPoint(
( 7 )