gpt4 book ai didi

java - 我无法让我的程序打印出闰年

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

我试图让它打印出我的程序的最后一个方法似乎无法让它做到这一点。我不知道该怎么办。我正在上在线类(class),所以没有人可以真正问我。我的老师需要三天时间才能回复。

import java.util.Scanner;

public class LeapYear {

public static void main(String[] args) {
displayInstructions();
int year = getYear();
isLeap(year);
}

public static void displayInstructions() {
System.out.println("This program asks you to enter a year as a 4 digit number. The output will indicate whether the year you entered is a leap year.");
}

public static int getYear() {
Scanner reader = new Scanner(System.in);
System.out.println("Enter a year: ");
int year = reader.nextInt();
return year;
}

public static boolean isLeap(boolean year) {
boolean isLeapYear = false;
if (year % 4 == 0 && year != 100) {
isLeap = true;

}
else {
isLeap false;
}



}
public static void displayResuls( boolean isLeap, boolean year) {
if (isLeap)
{
System.out.println("Year" +year+" is a Leap Year.");
}

else {
System.out.println("Year" +year+" is not a Leap Year");

}

}
}

最佳答案

你永远不会调用displayResuls(isLeap(year),year)

编辑:您的 displayResults 声明也是错误的,它应该是 intyear 而不是 booleanyear

关于java - 我无法让我的程序打印出闰年,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49592955/

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