Results 1 to 6 of 6
  1. #1
    dunboody is offline Member
    Join Date
    Sep 2011
    Posts
    10
    Rep Power
    0

    Default What's wrong with this program using escape characters?

    I keep getting "unclosed character literal" errors.

    public class Wonderland {

    private static final char HOOPLA = 'y';
    public static void main (String[] args) {

    System.out.println(HOOPLA + '/n' + HOOPLA + '/t' + HOOPLA + HOOPLA + '//' + '/'' + HOOPLA + '/b');
    }
    }

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,309
    Blog Entries
    7
    Rep Power
    20

    Default Re: What's wrong with this program using escape characters?

    The escape character is the backslash \ not the forward slash /

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    dunboody is offline Member
    Join Date
    Sep 2011
    Posts
    10
    Rep Power
    0

    Default Re: What's wrong with this program using escape characters?

    Gracias. Works fine, now. Although the backspace one '\b' isn't doing anything.

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,309
    Blog Entries
    7
    Rep Power
    20

    Default Re: What's wrong with this program using escape characters?

    Quote Originally Posted by dunboody View Post
    Gracias. Works fine, now. Although the backspace one '\b' isn't doing anything.
    How do you know? You didn't write something else following that \b ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    dunboody is offline Member
    Join Date
    Sep 2011
    Posts
    10
    Rep Power
    0

    Default Re: What's wrong with this program using escape characters?

    Yeah, I added some stuff after the backspace, and then it worked. So I suppose you can't use '\b' unless you have stuff written after it.

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,309
    Blog Entries
    7
    Rep Power
    20

    Default Re: What's wrong with this program using escape characters?

    Quote Originally Posted by dunboody View Post
    Yeah, I added some stuff after the backspace, and then it worked. So I suppose you can't use '\b' unless you have stuff written after it.
    Nope, that's not it; a backspace character doesn't delete a previous character, it just moves the cursor to a previous position (on most terminals).

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Replies: 4
    Last Post: 06-30-2011, 02:18 AM
  2. Escape Characters in xml
    By higashij in forum XML
    Replies: 2
    Last Post: 09-23-2010, 08:58 AM
  3. what the wrong in my program ><
    By MSs.Java in forum New To Java
    Replies: 4
    Last Post: 05-03-2010, 01:28 PM
  4. Need help with escape characters
    By jayjones149 in forum New To Java
    Replies: 1
    Last Post: 02-15-2010, 08:10 AM
  5. what is wrong with this program ?
    By Poor Bee in forum New To Java
    Replies: 1
    Last Post: 05-07-2008, 07:23 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
  •