Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Carriage Return

  1. #1
    Junior Member
    Join Date
    Jul 2021
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Carriage Return

    System.out.print("Hellow Healthly \r World");

    Ans should be World Healthly.....But Showing Only World!! Why?I am beginner in Java. Can anyone ans me why?

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Carriage Return

    I think it is because the print method does not flush the buffer without seeing a newline (\n) character. println will do that or add a \n at the end of the String being printed.

    When I execute the code on a Win10 system, I get this:
    Hellow Healthly 
     World

    What OS are you working on?
    I imagine consoles work differently than real printers where \r would move the print head back to the head of the current line and print over the top of what was printed there, while a console gors to the next line.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Removing Line feeds or carriage returns
    By Ron256 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: June 12th, 2014, 07:39 AM
  2. can i return two values from a return method?
    By tonu in forum Object Oriented Programming
    Replies: 4
    Last Post: January 1st, 2014, 11:02 AM
  3. Replies: 1
    Last Post: July 29th, 2013, 06:22 AM
  4. Curious about newline and carriage return
    By IHeartProgramming in forum Java Theory & Questions
    Replies: 4
    Last Post: November 25th, 2012, 08:13 PM
  5. Return Object does not return the expected output
    By Nour Damer in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 13th, 2011, 07:24 AM