public class vehicle{ public float journey; public int wheelNum; public int loadNum; public int drivespeed; public vehicle(){/*少了"l"字母*/ journey=100.3f; wheelNum=4; loadNum=1; }//vehice() public void driveAt(int speed){ if(speed>=60){ System.out.println("行车速度太快,容易造成事故!");/*";"要用半角" //如果要求的车速太快,则机动车自动以40单位速度行驶 drivespeed=40; } else{ System.out.println("你在安全行驶速度内行驶"); drivespeed=speed;/*speed中的"s"要小写*/ } }//driveAt() }/** vehicle */
现在就剩一个drivespeed=speed了 但是我也是那么改了啊, 怎么还是不好使呢!~!~
我在ms-dos下运行是时候 它提示我Exception in thread "main" java.lang.NoSuchMethodError: main谁能告诉我,这是因为什么!~!
public class vehicle{ public float journey; public int wheelNum; public int loadNum; public int drivespeed; public vehicle(){ journey=100.3f; wheelNum=4; loadNum=1; }//vehice() public static void main(String args[]){ vehicle v=new vehicle(); v.driveAt(78); v.driveAt(34); } public void driveAt(int speed){ if(speed>=60){ System.out.println("行车速度太快,容易造成事故!"); //如果要求的车速太快,则机动车自动以40单位速度行驶 drivespeed=40; } else{ System.out.println("你在安全行驶速度内行驶"); drivespeed=speed; } }//driveAt() }/** vehicle */ 通过
public class vehicle { public float journey; public int wheelNum; public int loadNum; public int drivespeed; public vehicle() { journey = 100.3f; wheelNum = 4; loadNum = 1; }//vehice()public void driveAt(int speed){ if(speed>=60){ System.out.println("行车速度太快,容易造成事故!"); // 如果要求的车速太快,则机动车自动以40单位速度行驶 drivespeed=40; } else{ System.out.println("你在安全行驶速度内行驶"); drivespeed=speed; } }//driveAt()} /** vehicle */public static void main(String[] args) { vehicle v = new vehicle(); v.driveAt(100); } } 行?速度太快,容易造成事故!
你重新编译一下 用 JBuilder or Eclipse不然太烦
public static void main(String[] args) { vehicle v = new vehicle(); v.driveAt(100); }作为一个class的入口 看看书就知道了.
不好意思,我真的是出学者,能不能告诉我JBuilder or Eclipse是什么??我不明白
楼上那个程序 public static void main(String[] args) { vehicle v = new vehicle(); v.driveAt(100); } 是,可以运行了,但是我的第二个输出就没有了啊~! System.out.println("你在安全行驶速度内行驶"); 这个就没有了
但是还有两个错误
我在运行是时候找到了
但是不理解di
driveSpeed=speed; 上面指的是(d)rive 错误了
System.out.println("行车速度太快,容易(造)成事故!") ;
(括号里面的是错误的) (d) (造)
但是我不知道是怎么个错了!!哪位大哥能告诉我 谢谢
public float journey;
public int wheelNum;
public int loadNum;
public int drivespeed;
public vehicle(){/*少了"l"字母*/
journey=100.3f;
wheelNum=4;
loadNum=1;
}//vehice()
public void driveAt(int speed){
if(speed>=60){
System.out.println("行车速度太快,容易造成事故!");/*";"要用半角"
//如果要求的车速太快,则机动车自动以40单位速度行驶
drivespeed=40;
}
else{
System.out.println("你在安全行驶速度内行驶");
drivespeed=speed;/*speed中的"s"要小写*/
}
}//driveAt()
}/** vehicle */
但是我也是那么改了啊, 怎么还是不好使呢!~!~
它提示我Exception in thread "main" java.lang.NoSuchMethodError: main谁能告诉我,这是因为什么!~!
public float journey;
public int wheelNum;
public int loadNum;
public int drivespeed;
public vehicle(){
journey=100.3f;
wheelNum=4;
loadNum=1;
}//vehice()
public static void main(String args[]){
vehicle v=new vehicle();
v.driveAt(78);
v.driveAt(34);
}
public void driveAt(int speed){
if(speed>=60){
System.out.println("行车速度太快,容易造成事故!");
//如果要求的车速太快,则机动车自动以40单位速度行驶
drivespeed=40;
}
else{
System.out.println("你在安全行驶速度内行驶");
drivespeed=speed;
}
}//driveAt()
}/** vehicle */
通过
public float journey; public int wheelNum; public int loadNum; public int drivespeed; public vehicle() {
journey = 100.3f;
wheelNum = 4;
loadNum = 1;
}//vehice()public void driveAt(int speed){
if(speed>=60){
System.out.println("行车速度太快,容易造成事故!");
// 如果要求的车速太快,则机动车自动以40单位速度行驶
drivespeed=40;
}
else{
System.out.println("你在安全行驶速度内行驶");
drivespeed=speed;
}
}//driveAt()}
/** vehicle */public static void main(String[] args) {
vehicle v = new vehicle();
v.driveAt(100);
}
}
行?速度太快,容易造成事故!
用 JBuilder or Eclipse不然太烦
vehicle v = new vehicle();
v.driveAt(100);
}作为一个class的入口
看看书就知道了.
public static void main(String[] args) {
vehicle v = new vehicle();
v.driveAt(100);
}
是,可以运行了,但是我的第二个输出就没有了啊~!
System.out.println("你在安全行驶速度内行驶");
这个就没有了
System.out.println("行车速度太快,容易造成事故!");
// 如果要求的车速太快,则机动车自动以40单位速度行驶
drivespeed=40;
}
else{
System.out.println("你在安全行驶速度内行驶");
drivespeed=speed;
}
作为条件分支语句,表示如果speed 〉= 60就做
System.out.println("行车速度太快,容易造成事故!");
// 如果要求的车速太快,则机动车自动以40单位速度行驶
drivespeed=40;
else里的语句是不会去做的。
你想,汽车以speed为100的速度去行使,那么就是说他
行车速度太快,容易造成事故
怎么可能既
行车速度太快,容易造成事故
又
你在安全行驶速度内行驶
v.driveAt(59);
你在安全行驶速度内行驶v.driveAt(61);
行车速度太快,容易造成事故!
你们知道我为什么要知道 你们的QQ吗,因为我在这上面的分没有了所以我怕我遇到难题的时候问不了,所以我想加你们Q
可以吗