显示错误: 找不到或无法加载主类 homework.MergeTwoList是什么原因?(MergeTwoList是我上个程序的名字)
package homework;

import java.util.Scanner;

public class DayCounter {
    int date, year, month, day, totalDays;

    DayCounter(int datePrint){
        date = datePrint;
        day = date % 100;
        month = (date / 100) % 100;
        year = date / 10000;
    }

    public int TotalDays() {
        int days = 0;          //当月天数
        totalDays = 0;
        for (int i = 1; i < month; i ++) {
            switch(i) {
            case 1:
            case 3:
            case 5:
            case 7:
            case 8:
            case 10:
            case 12:
                days = 31;
                break;
            case 4:
            case 6:
            case 9:
            case 11:
                days = 30;
                break;
            case 2:
                if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) {
                    days = 29;
                }
                else {
                    days = 28;
                }
            }
            totalDays += days;
        }
        totalDays = totalDays + day;
        return totalDays;
    }

}

class print{
    public static void main(String[] args){
        Scanner input = new Scanner(System.in);
        int date = input.nextInt();
        DayCounter day = new DayCounter(date);
        System.out.println("这是第" + day.TotalDays() + "天");

    }
}

1个回答

首先,你是用原生的 Java 命令执行的吗?如果是的话,这个文件保存路径应该是在一个 homework 文件夹下,然后文件名称为DayCounter.java.
其次,这个程序跟上个程序应该是没哟关系的,你直接用 IDE 来开发试试,例如 Eclipse 和 IDEA .

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问