java - System.out.printf format -
i have written down following code:
public class fractionofday { public static double fractionofday(double h, double m, int s, char ) { double y = -1; if (a == 'p' && h == 12) { double x = (h * 60 * 60) + (m * 60) + (s); y = x / 86400; } else if (a == 'p' && h != 12) { double x = ( (h + 12) * 60 * 60) + (m * 60) + (s); y = x / 86400; } else if (a == 'a' && h == 12) { double x = (m * 60) + (s); y = x / 86400; } else if (a == 'a' && h != 12) { double x = ( (h) * 60 * 60) + (m * 60) + (s); y = x / 86400; } return y; } public static void main(string[] args) { system.out.println(fractionofday(12, 0, 0, 'p')); } }
it prints out fraction of day has passed 12 . how can make print such table using printf
?
using calendar class
public static void main(string[] args) { calendar c = calendar.getinstance(); system.out.format("%tl:%tm %tp %10.4f%n", c, c, c, fractionofday( c.get(calendar.hour), c.get(calendar.minute), c.get(calendar.second), (calendar.am == c.get(calendar.am_pm)) ? 'a' : 'p')); }
Comments
Post a Comment