You are viewing a single comment's thread. Return to all comments →
You can use the .trim() method on your output string to remove the trailing space:
int runningTotal = a; String outputString = ""; int multiplier = 1;
for(int count = 1; count <= n; count++) { runningTotal += multiplier * b; outputString += runningTotal + " "; multiplier *= 2; }
System.out.println(outputString.trim());
Seems like cookies are disabled on this browser, please enable them to open this website
Java Loops II
You are viewing a single comment's thread. Return to all comments →
You can use the .trim() method on your output string to remove the trailing space:
int runningTotal = a; String outputString = ""; int multiplier = 1;
for(int count = 1; count <= n; count++) { runningTotal += multiplier * b; outputString += runningTotal + " "; multiplier *= 2; }
System.out.println(outputString.trim());