Page 2 of 2 FirstFirst 12
Results 21 to 27 of 27
  1. #21
    jlczuk is offline Senior Member
    Join Date
    Apr 2012
    Location
    New York State of Confusion, USA
    Posts
    137
    Blog Entries
    1
    Rep Power
    0

    Default Re: Problem with CHAR

    I'm not seeing what is wrong. So, you did good by printing a copy of the text String before the loop. For debugging purposes, you should print a copy of the result string afterward, before you exit the loop. And to help in between, you should print out the two characters at each loop iteration. I just noticed you reused tempChar, so you can use something like this:
    Java Code:
    System.out.println(String.format("%c : %c"), text.charAt(i), tempChar);
    Please post the output from running the program, it may help.

  2. #22
    Razion is offline Member
    Join Date
    Apr 2012
    Posts
    25
    Rep Power
    0

    Default Re: Problem with CHAR

    Not exactly sure what you were trying to do there, because that isn't a valid println. But I used:

    String test = Character.toString(text.charAt(i)) + tempChar;

    And got exactly whatever the input string was. :\

  3. #23
    jlczuk is offline Senior Member
    Join Date
    Apr 2012
    Location
    New York State of Confusion, USA
    Posts
    137
    Blog Entries
    1
    Rep Power
    0

    Default Re: Problem with CHAR

    I'm sorry, I had a typo in there because I didn't do it in an IDE and I was rushing. I had a paren in the wrong place. This should work:

    Java Code:
    System.out.println(String.format("%c : %c", 'a', 'b'));

  4. #24
    jlczuk is offline Senior Member
    Join Date
    Apr 2012
    Location
    New York State of Confusion, USA
    Posts
    137
    Blog Entries
    1
    Rep Power
    0

    Default Re: Problem with CHAR

    Crud...if you cut/paste that it won't work. This will:
    Java Code:
    System.out.println(String.format("%c : %c", text.charAt(i), tempChar));

  5. #25
    Razion is offline Member
    Join Date
    Apr 2012
    Posts
    25
    Rep Power
    0

    Default Re: Problem with CHAR

    Quote Originally Posted by jlczuk View Post
    Crud...if you cut/paste that it won't work. This will:
    Java Code:
    System.out.println(String.format("%c : %c", text.charAt(i), tempChar));
    Woah, incredibly weird. It returns:

    xkcd
    x : %
    k :
    c :
    d :

    And the blank spaces after three of the letters actually look like small squares with a > in them.

    Edit:
    Also, even more strangely... The integer value of those chars comes back as -1.

    Any ideas?
    Last edited by Razion; 04-26-2012 at 12:36 AM.

  6. #26
    jlczuk is offline Senior Member
    Join Date
    Apr 2012
    Location
    New York State of Confusion, USA
    Posts
    137
    Blog Entries
    1
    Rep Power
    0

    Default Re: Problem with CHAR

    I'm sure it has something to do with codepoints, I'm just not able to look into it tonite.

  7. #27
    Sierra is offline AN21XX
    Join Date
    Mar 2012
    Location
    Munich
    Posts
    297
    Rep Power
    3

    Default Re: Problem with CHAR

    No wonder you get bad output: You are using Character.getNumericValue() - I believe that actually is not what you want. It returns for '7' (int)7 and for '9' (int)9 and not the ASCII or Unicode value... just my two cents.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Printing Dec to Char Problem
    By rjagan in forum New To Java
    Replies: 6
    Last Post: 09-24-2011, 11:50 AM
  2. Problem with scanning char
    By danthegreat in forum New To Java
    Replies: 4
    Last Post: 09-09-2011, 07:01 PM
  3. char problem.
    By santa in forum New To Java
    Replies: 5
    Last Post: 02-18-2011, 12:24 AM
  4. replaceALL(char oldChar, char newChar) method
    By arson09 in forum New To Java
    Replies: 0
    Last Post: 04-28-2010, 05:48 AM
  5. Problem with if statement - Char
    By KardKaper in forum New To Java
    Replies: 8
    Last Post: 12-22-2009, 01:14 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
  •