This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to print in Double quotes ?

 
Neha Mohit
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi ,

How do we print in double quotes in java

for eg.

class Demo
{

public static void main(String a[])
{
System.out.prinltn("Hello");

}

}


I want o/p to be = "Hello" and not Hello

thanx in advance
[ June 05, 2006: Message edited by: Neha Mohit ]
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't understand your question.
 
Neha Mohit
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
simple keith , i want o/p to be Hello in double quotes like this "Hello"

the above code when executes gives o/p as Hello , i want the Hello in quotes
 
Wolfgang Obi
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how about this?

System.out.println((char)34+"Hello"+(char)34);

-W.O.
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I read your message before you added the code.

You can print a quote out by escaping it inside a String.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To elaborate: to include a double quote in a String literal, use the two characters \" :

System.out.println("\"Hello\"");
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For the complete list of charaters that require escaping see JLS
 
stephen shields
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
to be basic
to print " " i think you put

somestring = "\" Hello \"";
 
Neha Mohit
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to all of you.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic