How to Print Double Quotes in Java

Method 1 of 2:

Using Backslash as an Escape Character

  1. How to Print Double Quotes in Java Picture 1
    Type the escape character . As you know, the double quote symbol " has special meaning in Java (displaying text). Whenever you want to ignore one of these meanings, use the escape character (backlash). This character tells the compiler that the next character is part of an alternate instruction.
    1. Make sure you are hitting the backslash key, not the forward slash. The backslash key is next to the } key on most English keyboards.
  2. How to Print Double Quotes in Java Picture 2
    Type " to display the double quote. These two characters together are called an escape sequence. Each escape sequence has a special meaning. In this case, " just means "insert a double quote symbol here,", without interpreting it as the beginning or end of text.
    1. You will need to use this sequence for each individual double quote you want to display.
  3. How to Print Double Quotes in Java Picture 3
    Continue your code as usual. The escape sequence does not affect the rest of your code. There is no need to type anything else to return to normal programming.
  4. How to Print Double Quotes in Java Picture 4
    Remember to insert ordinary Java quotes as needed. One common mistake is to leave out the plain old " mark in your program. Remember that " is just for display, and does not remove the need to encase your display text in quotation marks. Here's an example:
    1. 1. The string for displaying "Hello" is "Hello"
    2. 2. To instruct the compiler to print this text, we wrap it in quotes: ""Hello"".
    3. 3. Here's what this looks like in a complete line of code:
      System.out.println(""Hello""); 
Method 2 of 2:

Using the ASCII Code

  1. How to Print Double Quotes in Java Picture 5
    Use char(34) to represent double quotes. Java can easily represent ASCII symbols using the char type. 34 is the ASCII code for the " symbol, so write char(34) to display " without using its special meaning.
    1. You can look up a symbol's ASCII code by searching for an ASCII code table online.
  2. How to Print Double Quotes in Java Picture 6
    Place this code outside of the print string. If you make the mistake of putting this code inside the string, your program will print it exactly as it appears in your program: char(34). Here's the proper method of displaying "Hello" (with the quotation marks) using this method:
    System.out.println((char)34+"Hello"+(char)34); 
4.2 ★ | 21 Vote

May be interested

  • How to Check Java Version on a MacPhoto of How to Check Java Version on a Mac
    this wikihow will teach you how to check what version of java you have installed on your mac by checking the system preferences, using the java website, or by using your mac's terminal. click . it's the apple icon in the upper-left of the...
  • How to Check Null in JavaPhoto of How to Check Null in Java
    a null indicates that a variable doesn't point to any object and holds no value. you can use a basic 'if' statement to check a null in a piece of code. null is commonly used to denote or verify the non-existence of something. within that...
  • How to Compile & Run Java Program Using Command PromptPhoto of How to Compile & Run Java Program Using Command Prompt
    while many programming environments will allow you to compile and run a program within the environment, you can also compile and run using command prompt. both windows and mac have their own versions of command prompt, although it is...
  • How to Check Your Java Version in the Windows Command LinePhoto of How to Check Your Java Version in the Windows Command Line
    this wikihow teaches you how to check what version of java you have installed on your windows computer using command prompt. click the windows start icon. it's the icon with windows logo. by default, it's in the bottom-left corner of the...
  • ! = and! == What is the difference in JavaScript?Photo of ! = and! == What is the difference in JavaScript?
    javascript includes operators like in other languages. an operator performs some operations on one or more operands (data values) and produces a result. today's article will help readers learn about 2! = and! == operators in javascript.
  • The difference between the == and === operators in JavaScriptPhoto of The difference between the == and === operators in JavaScript
    the == operator compares the abstract equality, that is, it performs the necessary type conversions before comparing the equality. the === operator compares strict equality, meaning that it will not perform type conversions.