用javac编译一个简单的java程序
我需要一些关于使用javac编译一个简单java程序的帮助 我有两个文件是我的老师给我的: Robot.java用javac编译一个简单的java程序,java,compiler-errors,Java,Compiler Errors,我需要一些关于使用javac编译一个简单java程序的帮助 我有两个文件是我的老师给我的: Robot.java class Robot { String name; int numLegs; float powerLevel; Robot(String name) { this.name = name; numLegs = 2; powerLevel = 2.0f; } Robot() { this(Standard Model);
class Robot {
String name;
int numLegs;
float powerLevel;
Robot(String name) {
this.name = name;
numLegs = 2;
powerLevel = 2.0f;
}
Robot() {
this(Standard Model);
}
void talk(String phrase) {
if (powerLevel = 1.0f) {
System.out.println(name + says + phrase);
powerLevel -= 1.0f;
} else {
System.out.println(name + is too weak to talk.);
}
}
void charge(float amount) {
System.out.println(name + charges.);
powerLevel = powerLevel + amount;
}
}
RobotWorld.java
class RobotWorld {
public static void main (String[] args) {
Robot c3po = new Robot("C3PO");
c3po.talk("'Hello, Java!'");
}
}
当我试图通过在命令提示符中键入“javacrobotworld.java”来编译它时,它只会返回一系列错误。我怎样才能解决这个问题?我已经安装了JDK 8
看起来所有双引号字符都已删除。我还在“powerLevel=”后面添加了另一个等号。试试这个:
class Robot {
String name;
int numLegs;
float powerLevel;
Robot(String name) {
this.name = name;
numLegs = 2;
powerLevel = 2.0f;
}
Robot() {
this("Standard Model");
}
void talk(String phrase) {
if (powerLevel == 1.0f) {
System.out.println(name + " says " + phrase);
powerLevel -= 1.0f;
} else {
System.out.println(name + " is too weak to talk.");
}
}
void charge(float amount) {
System.out.println(name + "charges.");
powerLevel = powerLevel + amount;
}
}
程序输出为:C3PO太弱,无法通话。看起来所有双引号字符都已删除。我还在“powerLevel=”后面添加了另一个等号。试试这个:
class Robot {
String name;
int numLegs;
float powerLevel;
Robot(String name) {
this.name = name;
numLegs = 2;
powerLevel = 2.0f;
}
Robot() {
this("Standard Model");
}
void talk(String phrase) {
if (powerLevel == 1.0f) {
System.out.println(name + " says " + phrase);
powerLevel -= 1.0f;
} else {
System.out.println(name + " is too weak to talk.");
}
}
void charge(float amount) {
System.out.println(name + "charges.");
powerLevel = powerLevel + amount;
}
}
程序输出为:C3PO太弱,无法说话。是的,字符串缺少双引号“”。 另外,标准模型代表什么
看起来您打算让默认构造函数使用参数调用构造函数,机器人名称为“Standard Model”?是的,字符串缺少双引号“”。 另外,标准模型代表什么
看起来您打算让默认构造函数使用参数调用构造函数,机器人名称为“Standard Model”?在我看来,您只是缺少了一堆字符串周围的“”和
=
,而不是=
,并且构造函数无效。您的任务是修复错误吗?因为它显然包含不正确的语法。powerLevel==1.0f在标准模型周围使用2=signsput双引号,所以这个(“标准模型”);我认为作业的目的是让你找出程序的错误,而不是在SOLooks上向我寻求帮助。你只是缺少了一堆字符串和=
而不是=
,以及一个无效的构造函数。您的任务是修复错误吗?因为它显然包含不正确的语法。powerLevel==1.0f在标准模型周围使用2=signsput双引号,所以这个(“标准模型”);我认为作业的目的是让你找出程序的错误,而不是在SOLooks上寻求帮助,比如标准模型是另一个没有引号的字符串。在字符串周围加上“”可以修复它。非常感谢。看起来标准模型是另一个没有引号的字符串。在字符串周围加上“”将其修复。谢谢。