⑴ java练习题
publicclassVehicle{
privateStringname;
privateStringgender;
privateintage;
privateStringdriverLicense;
privateStringplateNumber;
publicStringgetName(){
returnname;
}
publicvoidsetName(Stringname){
this.name=name;
}
publicStringgetGender(){
returngender;
}
publicvoidsetGender(Stringgender){
this.gender=gender;
}
publicintgetAge(){
returnage;
}
publicvoidsetAge(intage){
this.age=age;
}
publicStringgetDriverLicense(){
returndriverLicense;
}
publicvoidsetDriverLicense(StringdriverLicense){
this.driverLicense=driverLicense;
}
publicStringgetPlateNumber(){
returnplateNumber;
}
publicvoidsetPlateNumber(StringplateNumber){
this.plateNumber=plateNumber;
}
@Override
publicStringtoString(){
return"Vehicle[name="+name+",gender="+gender+",age="+age+",driverLicense="+driverLicense
+",plateNumber="+plateNumber+"]";
}
publicvoiddrive(){
System.out.println(name+"司机正在开"+plateNumber+"牌号的车。");
}
publicvoidstop(){
System.out.println(name+"司机把"+plateNumber+"牌号的车停了下来。");
}
publicbooleancheckName(Stringcheck){
if(this.name!=null&&this.name!=""){
returnthis.name.equals(check);
}
returnfalse;
}
publicbooleancheckPlateNumber(Stringcheck){
if(this.plateNumber!=null&&this.plateNumber!=""){
returnthis.plateNumber.equals(check);
}
returnfalse;
}
}
懒得写注释了
⑵ java基础练习题
intoldArr[]={1,3,4,5,0,0,6,6,0,5,4,7,6,7,0,5};
//建立一个list集合
ArrayList<Integer>list=newArrayList<Integer>();
for(inti=0;i<oldArr.length;i++){
if(oldArr[i]>0){
list.add(oldArr[i]);
}
}
intnewArr[]=newint[list.size()];
for(inti=0;i<list.size();i++){
newArr[i]=list.get(i);
}
//另一种写法,不过返回的应用型数据类型但是跟int也差不多
IntegerlistArr[]=list.toArray(newInteger[list.size()]);
⑶ java编程基础练习题
答案是抄C
A: num1=new double[num2+1];等价为:num1=new double[6];所以num1指向一个有袭6个元素的double型数组
B num2是一个整数
C:num1[num2]=num3;等价为:num1[5]=2.0;因为数组标识从0开始,所以num1[5]是最后一个元素
D: num1数组的第三个元素没有赋值,默认应该是0.0;