Instead, for example, "9/1/1996", I want my code to display "09/01/1996". I do not know how to describe my question in more detail. Here is my code for the MyDate class:
public class MyDate {
private int year;
private int month;
private int day;
public MyDate(int y, int m, int d){
year = y;
month = m;
day = d;
System.out.printf("I'm born at: %s\n", this);
}
public String toString(){
return String.format("%d/%d/%d", year, month, day);
}
}
And here is my main method:
public class MyDateTest {
public static void main(String[] args) {
MyDate birthday = new MyDate(31,12,1995);
}
}
ps I know there is a way to import the calendar, but I prefer to do it this way.
source
share