我在調用方法時遇到問題。例如,我想下面的程序有兩種方法:主調用方法
- 第一個是檢查年是飛躍與否,
- 第二個是在一個月 顯示的天數
我不能調用main
中的方法。
import java.util.Scanner;
public class LeapYearCheck {
public static void main(String[] args) {
LeapYearCheck ob = new LeapYearCheck();
ob.isLeapYear();
ob.daysInMonth();
}
static void isLeapYear() {
Scanner input = new Scanner(System.in);
int month = input.nextInt();
System.out.println("Enter a year: ");
int year = input.nextInt();
if (year % 4 == 0 || year % 400 == 0) {
System.out.println(year + " is leap year:");
} else {
System.out.println(year + " is not leap year:");
}
}
static void daysInMonth() {
Scanner input = new Scanner(System.in);
System.out.println("Enter a month :");
int month = input.nextInt();
int year = 0;
if (month == 2) {
System.out.println("There are 29 days in February: " + year + " year");
} else if (month == 1) {
System.out.println("The are 31 days in January " + year + " year");
} else if (month == 2) {
System.out.println("The are 28 days in February " + year + " year");
} else if (month == 3) {
System.out.println("The are 31 days in March " + year + " year");
} else if (month == 4) {
System.out.println("The are 30 days in April " + year + " year");
} else if (month == 5) {
System.out.println("The are 31 days in May " + year + " year");
} else if (month == 6) {
System.out.println("The are 30 days in June " + year + " year");
} else if (month == 7) {
System.out.println("The are 31 days in July " + year + " year");
} else if (month == 8) {
System.out.println("The are 31 days in August " + year + " year");
} else if (month == 9) {
System.out.println("The are 30 days in September " + year + " year");
} else if (month == 10) {
System.out.println("The are 31 days in October " + year + " year");
} else if (month == 11) {
System.out.println("The are 30 days in November " + year + " year");
} else if (month == 12) {
System.out.println("The are 31 days in December " + year + " year");
} else {
System.out.println("Invalid Month, Please enter a number between 1 & 12 Merci: ");
}
}
}
對不起,歡呼的隊友;/ – Kiril
歡呼菲利普我欣賞它 – Kiril
究竟是什麼問題?該程序對我來說運行得非常好(雖然有一些邏輯錯誤) –