英文:
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);
}
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论