Results 1 to 2 of 2
  1. #1
    allaudin's Avatar
    allaudin is offline Senior Member
    Join Date
    Apr 2013
    Posts
    271
    Rep Power
    0

    Post Inputmismatch for string

    How can I handle input mismatch for a string.I want only character input for a string .. thanks in advance ..

  2. #2
    monkeyjr97 is offline Senior Member
    Join Date
    Nov 2012
    Posts
    256
    Rep Power
    3

    Default Re: Inputmismatch for string

    Assuming you are using the scanner, which throws java.util.InputMismatchException if token retrieved does not match the pattern for the expected type, or that the token is out of range for the expected type.

    Then you can surround the code in a try catch block
    Java Code:
    try{
    
    //do what you want to do
    
    }catch(InputMissMatchException e) {
    
    //handle the error
    
    }
    Try looking at java API's InputMismatchException (Java 2 Platform SE 5.0)

Similar Threads

  1. Replies: 3
    Last Post: 02-10-2012, 07:26 PM
  2. Scanner: InputMismatch exception
    By Renxx in forum New To Java
    Replies: 4
    Last Post: 12-28-2011, 08:44 PM
  3. Replies: 1
    Last Post: 06-05-2011, 09:32 PM
  4. Replies: 12
    Last Post: 11-26-2010, 09:33 AM
  5. Replies: 1
    Last Post: 11-04-2010, 07:53 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
  •