Java程序设计模拟试题及答案
2、定义一个学生类(Student),属性包括:学号,班号,姓名,性别,年龄,班级总人数;方法包括:获得学号,获得班号,获得姓名,获得性别,获得年龄,获得班级总人数,修改学号,修改班号,修改姓名,修改性别,修改年龄以及一个toString()方法将Student类中的所有属性组合成一个字符串。定义一个学生数组对象。设计程序进行测试。
class student{
private String xuehao;
private String banhao;
private String xingming;
private String xingbie;
private int nianling;
public student(String x,String b,String m,String b1,int n){
this.xuehao = x;
this.banhao = b;
this.xingming = m;
this.xingbie = b1;
this.nianling = n;
}
public String getxuehao(){
return xuehao;
}
public String getbanhao(){
return banhao;
}
public String getxingming(){
return xingming;
}
public String getxingbie(){
return xingbie;
}
public int getnianling(){
return nianling;
}
public String toString(){
return xuehao+" "+banhao+" "+xingming+" "+xingbie+" "+nianling;
}
}
public class Dome4{
public static void main(String args[]){
student s1 = new student("02122168","12","安静","男",24);
System.out.println(s1.toString());
}
}
3、从键盘输入两个数,进行相加,显示和。当输入串中含有非数字时,通过异常处理机制,使程序能正确运行。
data segment
indata dw 2 dup(?)
outdata dw 1 dup(?)
notein1 db 'please input the first decimal number(0-99):$'
notein2 db 'please input the second decimal number(0-99):$'
noteout db 'the result of addition is:$'
notewarn db 'warning:wrong char!$'
noteagain db 'please input again:$'
data ends
show macro addr
mov ah,9h
lea dx,addr
int 21h
endm
code segment
assume cs:code,ds:data,es:data
main proc far
start:
push ds
sub ax,ax
push ax
mov ax,data
mov ds,ax
mov es,ax
show notein1
call crlf
call deci_input
mov indata,bx
call crlf
show notein2
call crlf
call deci_input
mov indata+2,bx
call crlf
mov ax,bx
add ax,indata
mov outdata,ax
show noteout
call crlf
call deci_output
ret
main endp
deci_input proc near
mov bx,0
newchar:mov ah,1
int 21h
cmp al,0dh
jz exit
sub al,30h
jl noteerr
cmp al,9d
jg noteerr
cbw
xchg ax,bx
mov cx,10d
mul cx
xchg ax,bx
add bx,ax
jmp newchar
noteerr:call crlf
show notewarn
call crlf
show noteagain
jmp newchar
exit: ret
deci_input endp
deci_output proc near
mov bx,outdata
mov cl,100d
mov ax,bx
div cl
mov bl,ah
mov dl,al
add dl,30h
call dispchar
mov ax,0
mov al,bl
cbw
mov cl,10d
div cl
mov bl,ah
mov dl,al
add dl,30h
call dispchar
mov dl,bl
add dl,30h
call dispchar
ret
deci_output endp
crlf proc near
mov dl,0ah
call dispchar
mov dl,0dh
call dispchar
ret
crlf endp
dispchar proc near
mov ah,2h
int 21h
ret
dispchar endp
code ends
end start
【Java程序设计模拟试题及答案】相关文章: