嗨所以我想假设优先级队列按降序实现Heap,从大到小,我希望用指数来实现。所以我完成了我的堆和优先级队列类,但现在在上课时我得到一个错误说
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
答案 0 :(得分:0)
你的构造函数中有一个拼写错误。您的类名为RelativeSource
,但在您的构造函数中,它显示为<DataGridTemplateColumn Width="190" Header="資格">
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<ComboBox
DisplayMemberPath="ItemName"
SelectedValuePath="ItemName"
SelectedValue="{Binding Path=Licence, UpdateSourceTrigger=LostFocus}"
ItemsSource="{Binding Path=DataContext.LicenceComboBox, RelativeSource={RelativeSource AncestorType=DataGrid}}" />
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>
。它成为一个无效的方法声明,因为它正在寻找一个返回数据类型,因为&#39;构造函数的名称&#39;您创建的与该类的名称不同。
编辑:
Exponents
。Exponent
Answer
的变量。