Results 1 to 3 of 3
  1. #1
    Souverain is offline Member
    Join Date
    Dec 2012
    Location
    Ottawa
    Posts
    4
    Rep Power
    0

    Default Problem with ASCII unicode

    Its me again ! I'm at my last number for my homework and i'm really stuck
    i need to get the ASCII code for a specific character entered by user. I have to use the 128 first ASCII character ... i have something like that but its not working ...

    Java Code:
     public static void main(String[] args) {
            Scanner clavier = new Scanner(System.in);
            int i;
            char unicastAchar;
            
            i = clavier.nextInt();
            
            System.out.println(i);
        }
    }

  2. #2
    kaydell2 is offline Senior Member
    Join Date
    Dec 2012
    Posts
    106
    Rep Power
    0

    Default Re: Problem with ASCII unicode

    Here are my suggestions:

    1. Before getting input from the user, prompt the user so that they know what to enter. A prompt like "Enter a single character" or something like that would be good.

    2. Input a whole String from the user using

    clavier.next()

    3. Get the first character from the string using the charAt() method. Remember that in Java, indexes start at zero.

    4. You'll want to convert the char gotten in step 3 above to be an int. Use a type cast to do this.

    int i = (int)ch;

    5. Then you can print the int and it will be the char code of the character that the user entered.

    If you have more questions. Please post another question on this thread.

  3. #3
    Souverain is offline Member
    Join Date
    Dec 2012
    Location
    Ottawa
    Posts
    4
    Rep Power
    0

    Default Re: Problem with ASCII unicode

    Thank you allot ! very helpful

Similar Threads

  1. Replies: 0
    Last Post: 06-30-2012, 07:53 PM
  2. Replies: 0
    Last Post: 02-22-2011, 08:27 AM
  3. Urgent Unicode/Ascii Problem
    By HackerOfDoom in forum New To Java
    Replies: 5
    Last Post: 03-23-2010, 04:26 PM
  4. Reading ASCII / Unicode character in Java
    By NGRaju in forum New To Java
    Replies: 2
    Last Post: 09-16-2008, 10:02 PM
  5. Unicode problem
    By rovshanb in forum JDBC
    Replies: 0
    Last Post: 02-14-2008, 06:41 AM

Posting Permissions

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