简体   繁体   中英

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? 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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