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 4 of 4

Thread: How to check if a user input is a char or a int

  1. #1
    Junior Member
    Join Date
    Aug 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to check if a user input is a char or a int

    so yeah i got this problem. i have to do a program and the first part of it is user input.
    i have 5 choices. 4 are an int and one is a char.
    heres the code i got so far.
    int reponse;
    System.out.println("1-Plus longue repetition de nucleotide");
    System.out.println("2-Liste des sous-sequences communes");
    System.out.println("3-Plus longue sous-sequence communes");
    System.out.println("4-Alignement optimal");
    System.out.println("q-Quitter");
    reponse = Keyboard.readInt();
    System.out.println(reponse);
    if (reponse == 1)
    {
    }
    if (reponse == 2)
    {
    }
    if (reponse == 3)
    {
    }
    if (reponse == 4)
    {
    }
    oh and btw the keyboard class is a class my teach gave me for my class cause we are complete beginners its basically used for user input.
    so as you can see i did an if for all the int reponse but what about if the user enters q? how do i check it?
    sorry if its in french but the code is still in english right.

    looking forward to your help

    Blackbird94


  2. #2
    Forum Squatter newbie's Avatar
    Join Date
    Nov 2010
    Location
    North Wales
    Posts
    661
    My Mood
    Stressed
    Thanks
    28
    Thanked 115 Times in 106 Posts
    Blog Entries
    1

    Default Re: How to check if a user input is a char or a int

    http://www.asciitable.com/index/asciifull.gif

    Answer is in the image really.
    Look at the decimal values.
    Please use [highlight=Java]//code goes here...[/highlight] tags when posting your code

  3. #3
    Junior Member
    Join Date
    Aug 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to check if a user input is a char or a int

    dosent seem like java is giving any value to "reponse" when i enter q. I tried printing it out it just gives 0

  4. #4
    Forum Squatter newbie's Avatar
    Join Date
    Nov 2010
    Location
    North Wales
    Posts
    661
    My Mood
    Stressed
    Thanks
    28
    Thanked 115 Times in 106 Posts
    Blog Entries
    1

    Default Re: How to check if a user input is a char or a int

    What errors are you getting? What did you try to solve the issue? What should It be doing?
    Please use [highlight=Java]//code goes here...[/highlight] tags when posting your code

Similar Threads

  1. Valid user input
    By ChristopherLowe in forum Java Code Snippets and Tutorials
    Replies: 1
    Last Post: June 21st, 2011, 04:53 PM
  2. User Input File Name
    By PineAppleKing in forum Java Theory & Questions
    Replies: 12
    Last Post: June 3rd, 2011, 10:23 AM
  3. How to get Char types from the user?
    By benglish in forum Java Theory & Questions
    Replies: 0
    Last Post: March 12th, 2011, 03:43 PM
  4. User Input Loop
    By cfmonster in forum Loops & Control Statements
    Replies: 7
    Last Post: August 24th, 2009, 01:52 PM
  5. How to check that console input should be integer only?
    By Konnor in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: February 2nd, 2009, 05:37 AM