class robot{
String status;
double speed;
double temperature;void checktemperature(){
if(temperature>600){
speed=5;
status="return home!";
}
}
void showattitude(){
System.out.println("status:"+status);
System.out.println("speed:"+speed);
System.out.println("temperature"+temperature);
}public static void main(String[] args){
robot henry=new robot();
henry.status="exploring";
henry.speed=3.33;
henry.temperature=300.2;henry.showattitude();
System.out.println("increase his temperature to 700.333");
henry.showattitude();
System.out.println("check his temperature");
henry.checktemperature();
henry.showattitude();
}
}为什么运行不了呢?
String status;
double speed;
double temperature;void checktemperature(){
if(temperature>600){
speed=5;
status="return home!";
}
}
void showattitude(){
System.out.println("status:"+status);
System.out.println("speed:"+speed);
System.out.println("temperature"+temperature);
}public static void main(String[] args){
robot henry=new robot();
henry.status="exploring";
henry.speed=3.33;
henry.temperature=300.2;henry.showattitude();
System.out.println("increase his temperature to 700.333");
henry.showattitude();
System.out.println("check his temperature");
henry.checktemperature();
henry.showattitude();
}
}为什么运行不了呢?
class robot改为 public class Robot并且保存的文件名为 Robot.java
status:exploring
speed:3.33
temperature300.2
increase his temperature to 700.333
status:exploring
speed:3.33
temperature300.2
check his temperature
status:exploring
speed:3.33
temperature300.2