• Register
0 votes
46 views
I want to initialize a String in Java, but that string needs to include quotes; for example, I was thinking it is easy to put these ” ” into another double quote. But that is a wrong procedure because  will be using two pair of double quotes and the message will lie in between these which will show an error, the compiler will think that my statement ends at second quote.

 

System.out.print(“”  hello world “”  ); 

how to solve this problem?

10 7 2
6,060 points

Please log in or register to answer this question.

1 Answer

0 votes
Hence to print double quotes along with our message we will use an escape character ( \ ) goes by the name of backslash character, before the inside double quote. 
This will tell the compiler to escape a character.

You can try like this :
System.out.print(” \”hello world \” “);

 

11 6 4
34,950 points

Related questions

0 votes
1 answer 10 views
10 views
I am finding difficulty with non repeated characters in a string in Java.
asked Sep 26, 2020 Daniel Anderson 4k points
0 votes
1 answer 10 views
10 views
I need to know how to remove the first cgaracter of a string in Java.
asked Sep 25, 2020 Daniel Anderson 4k points
0 votes
1 answer 6 views
6 views
I need to know how to print duplicate characters from string in Java.
asked Oct 3, 2020 Daniel Anderson 4k points
0 votes
1 answer 16 views
16 views
I am finding the answers in several blog for removing particular character from string in java.
asked Sep 29, 2020 Daniel Anderson 4k points
0 votes
1 answer 18 views
18 views
I need to know how to extract numbers from alphanumeric string in Java.
asked Sep 26, 2020 Daniel Anderson 4k points
0 votes
1 answer 9 views
9 views
I am finding the answers how to check string contains special characters in Java.
asked Sep 26, 2020 Daniel Anderson 4k points
0 votes
1 answer 10 views
0 votes
1 answer 24 views
24 views
I wrote a code in java to replace any charecter to a string: public class NewClass1 { public static void main(String[] args) { char ch='D'; String str="laptop"; ch = str + ch; System.out.println(ch); } } But it gives me error: Exception in thread " ... AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53: Java returned: 1 BUILD FAILED (total time: 1 second) How can I solve this problem?
asked Mar 14, 2020 LizzyM 6.1k points
0 votes
1 answer 8 views
8 views
I need to check if a number is a perfect squre in java.
asked Oct 5, 2020 Daniel Anderson 4k points
0 votes
1 answer 19 views
19 views
I was doing my java programming practice. I wrote a code to check if a charcter is a number: public static void main(String[] args) { String string = "-1234.15"; String numeric ; numeric = string.matches("-?\\d+(\\.\\d+)?"); if(numeric) System.out.println(string + " is a number"); else System.out.println(string + " is not a number"); } But it gives me error. Whats wrong in my code?
asked Mar 15, 2020 LizzyM 6.1k points