【发布时间】:2017-04-09 08:58:47
【问题描述】:
嗨,所以我想按从大到小的降序排列优先级队列实现堆,我想用指数来实现。所以我完成了我的堆和优先队列类,但现在在制作我的类时我收到一个错误提示
xponents.java:66: error: invalid method declaration; return type required
public Exponent(int num, int exponent, int x)
我不知道我哪里出错了
public class Exponents implements Comparable<Exponents>
{
private int num;
private int exponent;
private int x;
public Exponents(int num, int exponent, int x)
{
this.num = num;
this.exponent = exponent;
this.x = x;
}
public int Answer()
{
int x = Math.pow(num,exponent);
return x;
}
public String toString()
{
String s = ("Exponent: " + exponent + "\n Number: "+ num + "\nYour x is: )" + x);
return s;
}
public int compareTo(Answer e)
{
return this.x - o.x;
}
}
由于拼写错误,问题已解决,现在我收到更多错误,我不确定我写错了什么:
Exponents.java:83: error: cannot find symbol
public int compareTo(Answer e)
^
symbol: class Answer
location: class Exponents
Exponents.java:74: error: incompatible types: possible lossy conversion from double to int
int x = Math.pow(num,exponent);
^
Exponents.java:85: error: cannot find symbol
return this.x - o.x;
^
symbol: variable o
location: class Exponents
3 errors
【问题讨论】:
标签: java compiler-errors heap priority-queue comparable