I've just started out using lambdas and wrote this code to calculate if an input year is a leapyear or not, using lambdas.
I get the error "bad return type in lambda expressions void cannot be converted to int" and to no avail searched for answers.
import java.util.Scanner;
interface LeapYears {
int leapYear(int years);
}
public class LeapYear {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
LeapYears leap = (t) -> {
System.out.print("Year between 2012 and 2060: ");
int years = in.nextInt();
boolean x = years % 4 == 0,
y = years % 100 != 0,
z = years % 400 == 0;
boolean isLeapYear = (x && y) || z;
if (isLeapYear == true) {
return System.out.println(years + " Is a Leapyear");
} else {
return System.out.println(years + " is not a Leapyear");
}
}
}
}