In Java how do I format a number and preserve the format when converted to string?

I am entering values on the Table stringed array employing a loop, but I’m having trouble entering the particular numbers in a two digit format and then converting these folks to strings.I tried using the NumberFormat class recreate a minimum lots of digits, with such as myFormat.setMinimumIntegerDigits(2), but my compiler set it up errors.I’d like to see my numbers to become 01, 02, 03, 05, 06, 07, 08, 09, TEN, 11, and the like and possibly be stored to the array since strings.Can anyone help

int start_date = cal.get(Calendar.DATE);

for(int line = ONLY TWO; row < 6; row++)

for(int column = 0; column < 7; column++)

whenever (start_date < 1)

Tablerowcolumn = ” “;

else

Tablerowcolumn = Integer.toString(start_date) + ” “;

start_date +=1;

Method.out.println();

If you’re using the services of dates (which can be what a person show inside your example), you need to use the SimpleDateFormat school.So to format the day of the month:

SimpleDateFormat dateFormat = new SimpleDateFormat(“dd”);
Chain formattedDay = dateFormat.format(someDate);

This would always return the day in a couple digits.Same thing works with regard to month (“MM”).

Leave a Reply