Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

String Literals  RSS feed

 
Akshayan Venkatesh
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • 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...

 
Shaan Shar
Ranch Hand
Posts: 1249
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Akshayan Venkatesh

You are adviced not to log any thread twice. Wait for the resolution from other ranchers.
 
Sukhadev Patil
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • 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 ]
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • 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
 
fred rosenberger
lowercase baba
Bartender
Posts: 12542
48
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!