/* package whatever; // don't place package name! */

import java.util.regex.Pattern;

/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Pattern EOL = Pattern.compile("((\\\\r)?\\\\n)|\r?\n");
		final String escapedEOL = "\\\\n";

		System.out.println(EOL.matcher("asdf\njkl;").replaceAll(escapedEOL));
		System.out.println(EOL.matcher("asdf\n").replaceAll(escapedEOL));
		System.out.println(EOL.matcher("asdf\r\njkl;").replaceAll(escapedEOL));
		System.out.println(EOL.matcher("asdf\r\n").replaceAll(escapedEOL));
		System.out.println(EOL.matcher("asdf\\r\\njkl;").replaceAll(escapedEOL));        
		System.out.println(EOL.matcher("asdf\\r\\n").replaceAll(escapedEOL));

		
	}
}