Results 1 to 9 of 9
  1. #1
    hitesh_public is offline Member
    Join Date
    Aug 2010
    Posts
    9
    Rep Power
    0

    Default Why the last character doesn't wipe out by backspace?

    This is the code I am having trouble with

    Java Code:
    class MoveA {
      
      public static void main(String args[]) {
      
        for(int i=1;i<10;i++) {
          System.out.print("a");
          System.out.print("hello");
          System.out.print("\b");
        }
      }
    }
    The output of this code is:

    Java Code:
    ahellahellahellahellahellahellahellahellahello
    Why does the last character 'o' doesn't wipe out by back space character '\b'?

  2. #2
    alinaqvi90 is offline Member
    Join Date
    May 2010
    Posts
    32
    Rep Power
    0

    Default Add a space at the end of hello string

    System.out.print("hello ");

  3. #3
    hitesh_public is offline Member
    Join Date
    Aug 2010
    Posts
    9
    Rep Power
    0

    Default

    I mean to say that as all the 'o's in the output are deleted by the back space, why does the the 'o' in the last 'hello' doesn't wipe out.

  4. #4
    rohitjava is offline Member
    Join Date
    Aug 2010
    Posts
    13
    Rep Power
    0

    Post

    Quote Originally Posted by hitesh_public View Post
    This is the code I am having trouble with

    Java Code:
    class MoveA {
      
      public static void main(String args[]) {
      
        for(int i=1;i<10;i++) {
          System.out.print("a");
          System.out.print("hello");
          System.out.print("\b");
        }
      }
    }
    The output of this code is:

    Java Code:
    ahellahellahellahellahellahellahellahellahello
    Why does the last character 'o' doesn't wipe out by back space character '\b'?
    dude ur this question also amzed me.How Listen i have compiled ur code via cmd then the output is
    Java Code:
    ahellahellahellahellahellahellahellahellahello
    then i compiled ur code on TEXTPAD here the output is
    Java Code:
    ahellahellahellahellahellahellahellahellahello
    then i compiled ur code on IDE NETBEANS...see the output
    Java Code:
    ahelloahelloahelloahelloahelloahelloahelloahelloahello
    nw somebody first tell me what the hell is this . why different output for the same code on different editors.????????????

  5. #5
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    @OP: In your original post you describe '\b' as a back space character and the observed output is consistent with that: it is a backspace character not a delete-to-the-left character. It moves the cursor (the position the next character will be written), one place to the left but it does not itself write or erase anything.

    @rohit: Software displaying a bunch of characters will do so in whatever way it is felt most convenient. The console (which I think TextPad uses?) interprets the backspace as ... a backspace. What ur seeing with NB is a more Ozimandias approach: either because NB figures the programmer would like to see every character that was written, or because NB found it easier to implement a console component that way.

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default

    Quote Originally Posted by pbrockway2 View Post
    What ur seeing with NB ...
    txt spk?
    Shame on you!
    ;)

  7. #7
    rohitjava is offline Member
    Join Date
    Aug 2010
    Posts
    13
    Rep Power
    0

    Default

    please give me the simple and easy answer why there is so variation in output .......

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default

    pbrockway2 did.
    You're using a backspace...backspace != delete.
    The other o characters are being overwritten, not deleted.

  9. #9
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    Quote Originally Posted by Tolls View Post
    txt spk?
    Shame on you!
    ;)

    Whoops, my mistake. I wrote Ozimandius, but I meant Omar Khayyam who lived just down the road from Ur (though later). I was thinking of his description "The Moving Finger writes; and, having writ, Moves on: nor all thy Piety nor Wit Shall lure it back to cancel half a Line, Nor all thy Tears wash out a Word of it".

Similar Threads

  1. getting each character from keyboard
    By Sreejesh25 in forum New To Java
    Replies: 11
    Last Post: 01-25-2011, 01:08 PM
  2. ignore backspace
    By Kyle227 in forum New To Java
    Replies: 6
    Last Post: 05-16-2010, 09:34 PM
  3. Read from a certain character to a certain character
    By blackstormattack in forum New To Java
    Replies: 0
    Last Post: 03-16-2009, 11:36 AM
  4. Getting character set from a website
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-26-2007, 12:53 PM
  5. reading text character by character
    By bugger in forum New To Java
    Replies: 2
    Last Post: 11-09-2007, 08:54 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •