/*
  Suppose you have a lot of files in a directory named Exercisei_j, where
  i and j are digits. Write a program that pads a 0 before i if i is a single
  digit. For example, a file named Exercise2_1 in a directory will be renamed
  to Exercise02_1. Use the following command to run your program:

  java E12_28 *
*/

import java.io.File;

public class E12_28 {
  public static void main(String[] args) {
    for (String s: args) {
      File file = new File(s);
      if (s.matches(".*Exercise\\d_\\d+.*")) {
        StringBuilder sb = new StringBuilder(s);
        int index = sb.indexOf("Exercise");
        sb.insert((index + 8), "0");
        File newName = new File(sb.toString());
        file.renameTo(newName);
      }
    }
  }
}

@@ -462,57 +462,8 @@
 s);%0A
-      if (s.matches(%22.*Exercise%5C%5Cd_%5C%5Cd+.*%22)) %7B%0A  
     
@@ -515,45 +515,44 @@
     
-  int index = sb.indexOf(%22Exercise%22);
+if (s.matches(%22Exercise%5C%5Cd_%5C%5Cd+%22)) %7B
 %0A   
@@ -570,19 +570,9 @@
 ert(
-(index + 8)
+8
 , %220
@@ -573,24 +573,30 @@
 (8, %220%22);%0A  
+    %7D%0A
       File n
@@ -635,18 +635,16 @@
 ;%0A      
-  
 file.ren
@@ -659,24 +659,16 @@
 wName);%0A
-      %7D%0A
     %7D%0A  

Modify solution to fit the exercise specification more closely