运行此程序时,我不断收到相同的错误消息.这就是我得到的:
Exception in thread "main" java.lang.NoSuchMethodError: Customer.<init>(Ljava/lang/String;D)V
at Customer5.input(Customer5.java:35)<b>---(See below (code) to refer to lines 35 & 7)
at Customer5.main(Customer5.java:7)
Run Code Online (Sandbox Code Playgroud)
另一件事是"客户"类显示一条消息,上面写着"已定义客户类型".
import java.util.*;
public class Customer5 {
public static void main(String[] args) {
Customer[] customers=input();//This is line 7
customers=sort(customers);
output(customers);
}
public static Customer[] input(){
Scanner input =new Scanner(System.in);
int n;
String name;
double debt;
System.out.print("Enter number of customers :");
n=input.nextInt();
Customer[] customers=new Customer[n];
for(int i=0; i<n; i++){
System.out.print("Enter name:");
name=input.next();
System.out.print("Enter debt:");
debt=input.nextDouble();
customers[i]=new Customer(name, debt);//This is line 35 …Run Code Online (Sandbox Code Playgroud) 我正在开发一个程序,我必须计算文件中食物的频率,以便按降序对它们进行排序.
例如:如果我的文件有(披萨,冰淇淋,意大利面,披萨)
我希望我的程序打印类似于此的东西:
1 ice_cream 1意大利面2披萨
我正在使用冒泡排序算法,但似乎我遗漏了这个算法的工作原理.任何帮助将不胜感激!
在类Listabc中,我有两个局部变量和一个名为"compareTo"的方法.
class Listabc {
int count = 1;
String item;
int compareTo(Listabc listabc) {
return 0;
}
}
Run Code Online (Sandbox Code Playgroud)
在我的主要方法中,我有一个冒泡排序算法,按降序排序食品
public class MainMethod {
public static void main(String[] args) throws FileNotFoundException {
Scanner input = new Scanner(new BufferedReader(new FileReader("file.txt")));
List<Listabc> lists = new ArrayList<Listabc>();
for (int a = 0; a < lists.size() - 1; ++a) {
for (int b = a + 1; b < lists.size(); b++) {
if ((lists.get(b)).compareTo(lists.get(a)) > 0) {
Listabc …Run Code Online (Sandbox Code Playgroud)