It is a valid doubt and a year ago even I was facing such a similar doubt.
I found out that the best way to return such values from a method is to return it in type of an Object. In this example, if I were to return day, month and year then I would create a class as follows:
public class DateOfYear{
public int day;
public String month;
public int year;
public DateOfYear(int day, String month, int year){
this.day = day;
this.month = month;
this.year = year;
}
}
Now I will use this class DateofYear instantiate it and send values as an object. So, if you would like to get the Day of the month, the function will be as follows:
public DateOfYear dayInMonth(int day,int month,int year){
//....
return new DateOfYear(day,month,year);
}
and the calling function can simply display the current day as follows:
System.out.println("Day: "+dayInMonth(day,month,year).day);
Similarly for the method theDayAfter simply change the return type and return the object of type DateOfYear.
public DateOfYear theDayAfter(int day, int month, int year) {
day++;
int max=dayInMonth(day,month,year);
if(day>max)
{
month++;
if(month>12)
{
year++;
month=1;
day=1;
}
}
return new DateOfYear(day, month, year);
}
The method calling theDayAfter() can display the next day as follows:
System.out.println("Next Day: "+theDayAfter(day,month,year).day);
System.out.println("Month: "+theDayAfter(day,month,year).month);
System.out.println("Year: "+theDayAfter(day,month,year).year);