• Post Reply Bookmark Topic Watch Topic
  • New Topic

Carriage return is not working  RSS feed

 
vinoth vino
Ranch Hand
Posts: 67
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carriage return is not working when i execute the program it produce the n number of characters after "\r" in newline

Output

but i expect to come like below
Expected output

Can anyone help me?
1.png
[Thumbnail for 1.png]
Output
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16059
88
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see you are running this in Eclipse. Apparently the Eclipse output window does not support this properly.

When I compile and run your code in a command prompt window, I get exactly the output that you expected.
 
vinoth vino
Ranch Hand
Posts: 67
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jesper de Jong wrote:I see you are running this in Eclipse. Apparently the Eclipse output window does not support this properly.

When I compile and run your code in a command prompt window, I get exactly the output that you expected.


Vino wrote:Yup! Thanks a ton!! You are correct,when i compile the program in cmd it works very well. But why it doesn't work properly in eclipse? is there any solution to solve this?
working.png
[Thumbnail for working.png]
its working
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Don't use the CR (=(char)0x0d) (=\r) character unless you have been told specifically that it is required. As you can see, its behaviour is platform‑dependent. I tried your program on a Linux box and got
Vinojava programmer
Perl programmer
It is possible that your Eclipse installation has an option to take different line separator sequences and is set to “classic Mac” where the line end sequence is CR. I have no idea where that option is to be found. If you ever find it, try changing it to Windows/DOS (=CRLF =(char)0x0d(char)0x0a =\r\n) or Unix/Linux (=LF =(char)0x0a =\n). Newer Macs use the same line end as Linux.

Which operating systems were you using? [edit]cmd sounds like Windows[/edit]

I shall try duplicating this discussion in the IDEs forum; maybe somebody there will know more.
 
Knute Snortum
Sheriff
Posts: 4276
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I ran the code in Eclipse on Windows 7 and got the expected output.
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried searching Eclipse help and didn't find anything about line ends on the console. Maybe I searched wrongly.
 
Liutauras Vilda
Sheriff
Posts: 4917
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:I ran the code in Eclipse on Windows 7 and got the expected output.

I'm currently on Windows 7 professional but don't get expected output also. Eclipse Version: Luna Service Release 2 (4.4.2)
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!