收到一个错误:无法找到或加载主类Solution。

huangapple go评论90阅读模式
英文:

Receiving a Error: Could not find or load main class Solution

问题

以下是翻译好的代码部分:

出于某种原因在coderpad之外的任何地方这段代码都能正常工作在我使用过的每个 IDE 中当我运行它时它都能正常工作这对我来说毫无意义是静态设置有问题吗

class Main {

  public static class Restaurant {

    private final String name;
    private final String cuisine;
    private final double price;

    public Restaurant(String name,
                      String cuisine,
                      double price) {

      this.name = name;
      this.cuisine = cuisine;
      this.price = price;
    }

    public String getName() {
      return name;
    }

    public String getCuisine() {
      return cuisine;
    }

    public double getPrice() {
      return price;
    }
  }

  public static void main(String[] args) {

    int numRestaurants = 6;
    Restaurant[] myRestaurants = new Restaurant[numRestaurants];

    myRestaurants[0] = new Restaurant("Satisfactory Pita", "Mediterranean", 10);
    myRestaurants[1] = new Restaurant("Three Guys", "Burgers & Fries", 20);
    myRestaurants[2] = new Restaurant("China Panda", "Chinese", 30);
    myRestaurants[3] = new Restaurant("Puerto Sagua", "Cuban", 10);
    myRestaurants[4] = new Restaurant("Diya", "Indian", 40);
    myRestaurants[5] = new Restaurant("Shiraz Kabob Cafe", "Persian", 15);

    for(Restaurant myRestaurant : myRestaurants) {
      System.out.println(myRestaurant.name);
    }
  }
}
英文:

For some reason this works everywhere else except for coderpad. In every ide I had it works fine when I run it. This seems to make no sense to me. Is there an issue with the static setup or no?

class Main {
public static class Restaurant {
private final String name;
private final String cuisine;
private final double price;
public Restaurant(String name,
String cuisine,
double price) {
this.name = name;
this.cuisine = cuisine;
this.price = price;
}
public String getName() {
return name;
}
public String getCuisine() {
return cuisine;
}
public double getPrice() {
return price;
}
}
public static void main(String[] args) {
int numRestaurants = 6;
Restaurant[] myRestaurants = new Restaurant[numRestaurants];
myRestaurants[0] = new Restaurant("Satisfactory Pita", "Mediterranean", 10);
myRestaurants[1] = new Restaurant("Three Guys", "Burgers & Fries", 20);
myRestaurants[2] = new Restaurant("China Panda", "Chinese", 30);
myRestaurants[3] = new Restaurant("Puerto Sagua", "Cuban", 10);
myRestaurants[4] = new Restaurant("Diya", "Indian", 40);
myRestaurants[5] = new Restaurant("Shiraz Kabob Cafe", "Persian", 15);
for(Restaurant myRestaurant : myRestaurants) {
System.out.println(myRestaurant.name);
}
} 
}

答案1

得分: 0

class Solution {

    public static class Restaurant {

        private final String name;
        private final String cuisine;
        private final double price;

        public Restaurant(String name,
                          String cuisine,
                          double price) {

            this.name = name;
            this.cuisine = cuisine;
            this.price = price;
        }

        public String getName() {
            return name;
        }

        public String getCuisine() {
            return cuisine;
        }

        public double getPrice() {
            return price;
        }
    }

    public static void main(String[] args) {

        int numRestaurants = 6;
        Restaurant[] myRestaurants = new Restaurant[numRestaurants];

        myRestaurants[0] = new Restaurant("Satisfactory Pita", "Mediterranean", 10);
        myRestaurants[1] = new Restaurant("Three Guys", "Burgers & Fries", 20);
        myRestaurants[2] = new Restaurant("China Panda", "Chinese", 30);
        myRestaurants[3] = new Restaurant("Puerto Sagua", "Cuban", 10);
        myRestaurants[4] = new Restaurant("Diya", "Indian", 40);
        myRestaurants[5] = new Restaurant("Shiraz Kabob Cafe", "Persian", 15);

        for(Restaurant myRestaurant : myRestaurants) {
            System.out.println(myRestaurant.name);
        }
    } 
}
英文:

According Languages support for run Java.

> You should define a public class named Solution with a public static
> void main.

Rename the class to Solution, like:

class Solution{
public static class Restaurant {
private final String name;
private final String cuisine;
private final double price;
public Restaurant(String name,
String cuisine,
double price) {
this.name = name;
this.cuisine = cuisine;
this.price = price;
}
public String getName() {
return name;
}
public String getCuisine() {
return cuisine;
}
public double getPrice() {
return price;
}
}
public static void main(String[] args) {
int numRestaurants = 6;
Restaurant[] myRestaurants = new Restaurant[numRestaurants];
myRestaurants[0] = new Restaurant("Satisfactory Pita", "Mediterranean", 10);
myRestaurants[1] = new Restaurant("Three Guys", "Burgers & Fries", 20);
myRestaurants[2] = new Restaurant("China Panda", "Chinese", 30);
myRestaurants[3] = new Restaurant("Puerto Sagua", "Cuban", 10);
myRestaurants[4] = new Restaurant("Diya", "Indian", 40);
myRestaurants[5] = new Restaurant("Shiraz Kabob Cafe", "Persian", 15);
for(Restaurant myRestaurant : myRestaurants) {
System.out.println(myRestaurant.name);
}
} 
}

huangapple
  • 本文由 发表于 2020年10月18日 03:03:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/64406259.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定