title: markdown algorithm java; converter problems
body: <pre><code>public class Md2html {
      public static void main(String[] args) throws IOException {
  
         String stringToConvert = new Scanner(System.in).nextLine();
         System.out.println(convert(stringToConvert));
  
      }
  
      public static String convert(String str) {
  
           if (str.equals("# "))
               System.out.println(" ");
  
           Pattern pattern = Pattern.compile("(#+[^#]+)");
           Matcher matcher = pattern.matcher(str);
  
           while (matcher.find()) {
               String str1 = matcher.group(1);
               if(str1.replaceFirst("#+", "").length() == 0 ||
                  str1.replaceFirst("#+", "").matches("[\\s]+")) 
                        continue;
               int n = str1.length() - str1.replaceFirst("#+", "").length();
               System.out.println("&lt;h" + n + "&gt;" + str1.substring(n) + 
                                  "&lt;/h" + n + "&gt;");
  
               double carac;
               carac = str.charAt(0);
               if(carac&gt;65 &amp; carac &lt;=90) {
                    System.out.print("&lt;p&gt;");
                    System.out.println(str);
                    System.out.println("&lt;p&gt;");
               }
          }
  
          return ("");
      }     
  }
  </code></pre>
  
  <p>Ok, so now I have an algorithm that converts # to &lt; h1> &lt; h2> depending on the number of #...I'm now trying to add &lt; p> at the beginning of a paragraph and &lt; /p> at the end of it. For some reason,the second part of the converter, which is supposed to add &lt; p> at the beginning and &lt; /p> at the end of a paragraph doesnt seem to work (it's the code starting with double carac). Can someone tell me what I'm doing wrong???</p>