gpt4 book ai didi

java - 在类 ActivityTime 中找不到 Main 方法,请将 main 方法定义为 : public static void main(String[] args)

转载 作者:行者123 更新时间:2023-12-01 12:08:25 30 4
gpt4 key购买 nike

我在 http://www.hackerearth.com/problem/algorithm/roys-life-cycle/ 上测试了我的程序。但是,我总是收到错误:在类 ActivityTime 中找不到主方法,请将主方法定义为:public static void main(String[] args)这是我的程序

import java.util.Scanner;

/**
* Created by DUY on 10/12/2014.
*/
class EatSleepCode {
public static void main(String[] args){
int numberDay = 0;
int numberMinuteOfDay = 18;

Scanner input = new Scanner(System.in);
numberDay = input.nextInt();
input.nextLine();

String[] str = new String[numberMinuteOfDay];

for(int i = 0; i < numberDay; i++){
str[i] = input.nextLine();
}

ActivityTime code = new ActivityTime(numberDay,str,'C');

code.findLongestTime();
}
}

class ActivityTime{
public int longestTimeOfDay;
public int longestTimeOfTotal;
public int numberDay;
public String[] str;
public char act;
public ActivityTime(int numberDay, String[] str, char act){
this.numberDay = numberDay;
this.str = str;
this.act = act;
}
public void findLongestTime(){
int tmp1 = 0, tmp2 = 0;
for(int i = 0; i < numberDay; i++){
tmp1 = 0;
for(int j = 0; j < str.length; j++){
if(str[i].charAt(j) != act){
tmp1 = 0;
tmp2 = 0;
}
else {
tmp1 ++;
tmp2 ++;
}
if(tmp1 > longestTimeOfDay){
longestTimeOfDay = tmp1;
}
if(tmp2 > longestTimeOfTotal){
longestTimeOfTotal = tmp2;
}
}
}
System.out.println(longestTimeOfDay + " " + longestTimeOfTotal );
}
}

你能帮我解决这个错误吗?非常感谢

最佳答案

您应该将这些类分成两个文件,一个名为 EatSleepCode.java,另一个名为 ActivityTime.java

完成此操作后,您将更清楚将哪个类作为主类运行。它是 EatSleepCode ,其中包含 public static void main ,因此大概这就是您想要作为主类的内容; ActivityTime 没有这样的方法,这就是为什么你不能将其作为主类运行。这就是您所得到的错误的含义。

关于java - 在类 ActivityTime 中找不到 Main 方法,请将 main 方法定义为 : public static void main(String[] args),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27404683/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com