[英]Illegal start of type error when compiling
Am writing a program which allows two superheros to fight.我正在编写一个允许两个超级英雄战斗的程序。 However when I try to compile the I get an illegal start type error.
但是,当我尝试编译时,出现非法启动类型错误。
public class Fight {
public static void main(String [] args); {
Superhero Spiderman = new Superhero();
Superhero TheHumanTorch = new Superhero(21);
}
public Spiderman fight(TheHumanTorch opponet); {
System.out.Println(TheHumanTorch);
}
private void powerUp(100); {
Spiderman Strength = Srength + 100;
}
public Spiderman fight(TheHumanTorch opponet); {
System.out.Println(Spiderman);
}
}
public class Superhero {
public String Name;
private int Strength;
public Superhero(String n, int s) {
Name = n;
Strength = s;
}
public Superhero(String n) {
Name = n;
Strength = 10;
}
private void powerUp(int powerUp) {
Srength = Srength + powerUp;
}
}
public Superhero fight(Superhero opponet) {
if (this.Strength > opponet.Strength) {
return this;
} else {
return opponet;
}
}
public String toString() {
if (this.Stength) {
return "Superhero";
} else {
return "Superhero opponet";
}
}
}
It is being caused by this code:这是由以下代码引起的:
private void powerUp(100); {
Spiderman Strength = Srength + 100;
}
You need to provide the type and parameter name to the method.您需要为方法提供类型和参数名称。 I'm guessing you meant to provide something like
amount
to it.我猜你的意思是提供类似
amount
东西。 Something like this could compile if a class named Spiderman
was available and Srength
was available to the scope of this method:如果名为
Spiderman
的类可用并且Srength
可用于此方法的范围,则可以编译这样的东西:
private void powerUp(int amount) {
Spiderman Strength = Srength + amount;
}
Another issue is that you have too many brackets in your class definition:另一个问题是您的类定义中有太多括号:
private void powerUp(int powerUp) {
Srength = Srength + powerUp;
}
}
// This is the closing bracket for the class definition.
You should remove that extra bracket.您应该删除那个额外的支架。 Your code below is not being included in the class definition.
您下面的代码未包含在类定义中。
There are plenty of other issues, as well.还有很多其他问题。 When you try to compile, the compiler will help you discover these problems and give you context as to how to fix them.
当您尝试编译时,编译器将帮助您发现这些问题,并为您提供有关如何修复它们的上下文。
You seem like you may be new to programming, so you may just be using an editor like Notepad or VI.您看起来可能是编程新手,因此您可能只是在使用记事本或 VI 之类的编辑器。 A lot of developers (most) use a tool called an IDE , which makes a developer's life much better.
许多开发人员(大多数)使用称为IDE的工具,这使开发人员的生活变得更好。 A few examples would be:
一些例子是:
As Andreas mentioned, your main
and other methods have semicolons when they should not:正如安德烈亚斯所提到的,您的
main
方法和其他方法在不应该使用分号时使用分号:
public static void main(String [] args); {
Should be:应该:
public static void main(String [] args) {
There are plenty of other issues that your compiler (or IDE) will catch that you will need to address, too.您的编译器(或 IDE)还会发现许多其他问题,您也需要解决这些问题。 Here are a just a few examples your compiler will find, that you will have to figure out how to fix:
以下是您的编译器会找到的几个示例,您必须弄清楚如何修复:
Spiderman
isn't a defined class Spiderman
不是一个定义的类TheHumanTorch
isn't a defined class TheHumanTorch
不是一个定义的类Println
isn't a method defined on java.io.PrintStream
(your System.out.Println
call) Println
不是在java.io.PrintStream
定义的java.io.PrintStream
(您的System.out.Println
调用)Srength
and Stength
will not be resolved. Srength
和Stength
不会解决。 You probably mean Strength
Strength
I recommend that you slowly iterate over your code with a Java resource nearby to help guide you through some examples and compare what you wrote vs. how the examples are written.我建议您使用附近的 Java 资源慢慢迭代您的代码,以帮助指导您完成一些示例,并比较您编写的内容与编写示例的方式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.