简体   繁体   English

我不知道如何在第四种方法中打印出第三种方法

[英]I can't figure out how to get the third method to print out in the fourth method

The Third Method is supposed to figure out if the year is a leap year or not and the fourth is supposed to print the info out through a string? 第三种方法应该确定年份是否为a年,而第四种方法应该通过字符串将信息打印出来? But I don't know how? 但是我不知道怎么办? AFTER EDIT* Still giving me an errors. 编辑后*仍然给我一个错误。 Don't know why 不知道为什么

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) {
    if (year % 4 == 0 && year % 100) {
        isleap = true;

    }
    else {
        return false;
    }



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

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

   }

    }
}

用与将getYear()的结果存储到变量中并将该值作为参数传递给isLeap的方法相同,您需要对isLeap的结果进行相同的操作并将该值作为参数传递给displayResults

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM