I have this program to print the data in desired format. but I am having difficulty to get it working.
here is my code and output:
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
public class TestingStuff {
public static void main(String[] args){
Calendar calendar = Calendar.getInstance();
calendar = new GregorianCalendar(2014, 07, 18);
Date startDate = calendar.getTime();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM/dd/yy");
String formatted = simpleDateFormat.format(startDate);
String result="";
String header2=String.format("%s %20s %20s %20s%n", "Account","Date","Hours","Skill");
result+=header2;
result+="-----------------------------------------------------------------------\n";
result+=String.format("summary %20s%n",formatted);
result+=String.format("Totabl Billable: %25s%n", 40);
result+=String.format("Total Non-Billable: %25s%n", 0);
result+=String.format("Total Hours %25s%n", 40);
System.out.println(result);
}
}
Output:
Account Date Hours Skill
-----------------------------------------------------------------------
summary 08/18/14
Totabl Billable: 40
Total Non-Billable: 0
Total Hours 40
Expected output:
Account Date Hours Skill
-----------------------------------------------------------------------
summary 08/18/14
Totabl Billable: 40
Total Non-Billable: 0
Total Hours 40
As you can see the numbers are not centered with respect to tab headers. I am also hard coding the number of spaces such as (%20s) which I guess is not the right way. Is there a way to tell
to format automatically with centering?
tab,but that is giving separation for the headers but not for the rows below it