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
  • 123,543
  • 24
  • 232
  • 276
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
  • 155,977
  • 14
  • 207
  • 269
0

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

Jack
  • 128,551
  • 28
  • 227
  • 331