• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

String Literals

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please reply this Question and How is Functioning ?
It will display the answer hai.

class Q15
{
public static void main(String[] args)
{
System.out.print("\nab");
System.out.print("\bsi");
System.out.print("\rha");

}

}
if i change the order of system.out.the answer will change. How to functioning of this evaluations such as backspace and newline and garriage return.

I expecting the answres early as possible...

 
Ranch Hand
Posts: 1252
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Akshayan Venkatesh

You are adviced not to log any thread twice. Wait for the resolution from other ranchers.
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
class Q15
{
public static void main(String[] args)
{
System.out.print("\nab");// due to '\n' character it goes to new line and on new line prints 'ab'

System.out.print("\bsi");// due to '\b' character, character 'b' will be deleted and 'si' will be appened so output become 'asi'

System.out.print("\rha");// due to '\r' character, it starts printing from first character and overwrites previous output so 'ha' replaces 'as' and output is 'hai'

}

}
[ April 13, 2006: Message edited by: Sukhadev Patil ]
 
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
wow, I'm the second half of Java at Lamar University, and never have heard of this kind of string manipulation, where can i learn more at

i mean i know about \n and there is one to tab too....

but not \b or \r

justin
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is not really string manipulation. no string is being changed.
the \r and \b come from the old days, when printers had a print head. characters were printed one at a time across the line.

if you've ever seen an old IBM Selectric typewriter, you know what i mean.

anyway, there were only certain characters you could print. if you wanted to underline a word, you had to print a character, then back up a space, and print an underscore in the same spot.

that's where the \b comes from - it 'backspaced' the printer head one character. there was also a \r which would return the head to the start of the same line. a line-feed character would advance the paper one line, but not move the head.

just about any java book should talk about escape characters.
 
reply
    Bookmark Topic Watch Topic
  • New Topic