• 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

Carriage return is not working

 
Ranch Hand
Posts: 67
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 79240
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I ran the code in Eclipse on Windows 7 and got the expected output.
 
Campbell Ritchie
Marshal
Posts: 79240
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 8863
637
Mac OS X VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
That new kid is a freak. Show him this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic