java - How can I make a list print out A1-A6, then B1-B6, etc? -
i'm creating vending machine has print out list of options user can enter, problem facing can not print need input item. program gets items print text file. example can print this:
almond joy
mentos
skittles
but need this:
a1: almond joy
a2: mentos
a3: skittles
so on , forth through a6, go on b1-b6, on , forth. how can print out in fashion?
you need generate prefix yourself:
int num_columns = 6; char rowprefix = 'a'; int colprefix = 1; scanner s = new scanner("/path/to/file.txt"); while (s.hasnextline()) { string product = s.nextline(); system.out.println(string.valueof(rowprefix) + colprefix + ": " + product); colprefix++; if (colprefix == num_columns) { colprefix = 1; rowprefix++; } }
Comments
Post a Comment