maxInt = (maxInt - maxInt) + k;
(maxInt - maxInt) is always zero, so something is wrong here.
You can use maxInt just as a trigger, using value>=maxInt
instead ==
, and then you could just loop, as you say.
Then you only would need two loops: the outer one iterating for each line and the inner one for each bar of the graph, something like:
//Given the max value of the graph maxInt
for (int i=maxInt;i>0;i--) {
for (int j=0;j<count.length;j++) {
if (count[j]>=i) {
System.out.print(" * ");
} else {
System.out.print(" ");
}
}
System.out.println("NEWLINE");
}
I think this way is more elegant (as it's simpler and easier to understand.