Period ofYears() method in Java with Examples
The ofYears(int numberOfYears) method of Period class is used to get a period from the given number of years as parameter. The obtained period will represent the number of years. The unit month and days shall remain 0.
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.
public static Period ofYears(int numberOfYears)
Parameters: This method accepts a single parameter numberOfYears of Integer type which represent the number of Years. It can be both negative and positive.
Return value: This method must return a Period, representing the number of Years.
Exception: This method does not throw any exception.
Below programs illustrate the ofYears() method of Period in Java:
Years: 5 Months: 0 Days: 0
Years: -10 Months: 0 Days: 0