Hello Everyone, I am facing some issues while I’m coding an IDE. Let’s say I have the Hello, World Pascal program on a string:
String sourceCode = "program Hello;\nbegin\nwriteln ('Hello, world.');\nend.";
If I do System.out.println(sourceCode); the output shows:
program Hello;
begin
writeln ('Hello, world.');
end.
reat, but I want to show new lines as \n
. I tried:
sourceCode = sourceCode.replaceAll(System.lineSeparator(), "\\n");
But then System.out.println(sourceCode);
outputs:
program Hello;nbeginnwriteln ('Hello, world.');nend.
How can I achieve that? Full demo:
public class PrintPascalHelloWorld {
public static void main(String[] args) {
String sourceCode = "program Hello;\nbegin\nwriteln ('Hello, world.');\nend.";
System.out.println(sourceCode);
sourceCode = sourceCode.replaceAll(System.lineSeparator(), "\\n");
System.out.println(sourceCode);
}
}
Can anyone suggest me? I’m able to compile and run the program using by interviewbit online compiler.