reset password
Author Message
gchan10
Posts: 27
Posted 14:29 May 23, 2016 |

For this problem, how would we format the table? Do we use printf or do we hard-code the table?

kknaur
Posts: 540
Posted 14:32 May 23, 2016 |

printf Will give you the best options for making it look nice.

gchan10
Posts: 27
Posted 14:40 May 23, 2016 |

In that case, could you put a variable inside the printf formatting? For example, would it allow me to do %Ns where the letter N is a variable?

kknaur
Posts: 540
Posted 14:46 May 23, 2016 |

Well remember that the format part of printf(format, args1, args2, ... , argsn) must be a String.  Taking your example, you could build a string using the variable and concatenation.

int n = 6; //column width, (can be dynamically calculated given the table data)
String output =  "%" + n + "s"; 
System.out.printf( output, someItemToFormat);
kknaur
Posts: 540
Posted 15:02 May 23, 2016 |

Also keep in mind that the cookie names will change, so the column widths should be variable.

velder0
Posts: 16
Posted 22:56 May 24, 2016 |

how do I use the String name instead of the Int value of the packages sold when I'm finding the highest and lowest sold?