Skip to content

Commit

Permalink
step 4
Browse files Browse the repository at this point in the history
  • Loading branch information
mnishizawa committed Mar 10, 2016
1 parent 4914fc3 commit b616162
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@ public class Main {

public static void main(String[] args) {
for (int i = 0; i < 20; i++) {
System.out.println("Hello " + args[0] + "!");
System.out.println(pad(i+1, 2)+") Hello " + args[0] + "!");

This comment has been minimized.

Copy link
@mnishizawa

mnishizawa Mar 10, 2016

Author Member

Example comment on code quality:
Magic number, declare it as a constant or give it a variable name so we know what it means.

static final int PLACES=2;  //this is a constant in java

// now where you call "pad", instead of using a number, use the constant
pad(i+1, PLACES);
}
}

private static String pad(int number, int places) {
if(String.valueOf(number).length() < places) {
return String.format("%0"+places+"d", number);
}

return String.valueOf(number);
}
}

0 comments on commit b616162

Please sign in to comment.