Display the following text (two lines):
This is a Windows path: "C:\Program Files\Java\jdk1.8.0_172\bin"
This is a Java string: \"C:\\Program Files\\Java\\jdk1.8.0_172\\bin\"
Hint:
\” – Insert a double quote character in the text at this point.
\\ – Insert a backslash character in the text at this point.
Requirements:
1. The program should output text.
2. Two lines must be displayed.
3. The first line of text should be: This is a Windows path: "C:\Program Files\Java\jdk1.8.0_172\bin"
4. The second line of text should be: This is a Java string: \"C:\\Program Files\\Java\\jdk1.8.0_172\\bin\"
package com.codegym.task.task03.task0316;
/*
Escaping characters
*/
public class Solution {
public static void main(String[] args) {
System.out.println("This is a Windows path:\"C:\Program Files\Java\jdk1.8.0_172\bin");
System.out.println("This is a Java string:\"C:\\Program Files\\Java\\jdk1.8.0_172\\bin\"");
}
}
Mohamad
Level 4
I did not understand what does that mean or what to do with it can someone explain this to me please....
Resolved
Comments (3)
- Popular
- New
- Old
You must be signed in to leave a comment
Mohamad
16 November 2018, 18:53
thank you very much i appreciate it
0
Michael Martin
16 November 2018, 00:31
If you want to print special characters like \ or ", you have to 'escape' them.
For instance, System.out.println("\"") will display "
and System.out.println("\\") will display \
You have to add a backslash \ to the println statement in front of the \ or " if you want to display it.
+1
divya
15 February 2019, 09:12
can you be more precise about 'escape' them?
0