0

I have this code for converting a markdown string to html:

public static String convert(String str) {
    if (str.equals("# "))
        return " ";

    if (str.matches("#+.+")) {
        int n = str.length() - str.replaceFirst("#+", "").length();
        return "<h" + n + ">" + str.substring(n) + "<h" + n + ">";
    }

    return str;
}

What I would like to know is how to get this class to get its string from keyboard entry?

arshajii
  • 127,459
  • 24
  • 238
  • 287
Arn0ld_t
  • 29
  • 8

2 Answers2

2

You could use Scanner.nextLine():

String stringToConvert = new Scanner(System.in).nextLine();
System.out.println("Converted string is: " + convert(stringToConvert));
Reimeus
  • 158,255
  • 15
  • 216
  • 276
0

Just to keep it simple you can go by Console.readLine().

Jack
  • 131,802
  • 30
  • 241
  • 343