Results 1 to 4 of 4

Thread: Input Error

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

    Default Input Error

    Java Code:
    public static void main(String[] args) throws IOException {
    		Scanner input = new Scanner(System.in);
    		System.out.print("Enter String to Search : ");
    		String stringToSearch = input.next();
    		System.out.println("Enter Character to Find Repitition : ");
    		String characterToSearch = input.next(); 	/* doesn't take input here */
    
    		SearchingString searchingString = new SearchingString(stringToSearch,
    				characterToSearch.charAt(0));
    		input.close();
    		searchingString.mostRepeatedCharacters();
    		System.in.read();
    
    	}
    It does not take input at characterToSearch = input.next(); . what's wrong with this ? also tell me is there any method to take characters as input directly ... I changed the string to characters . Thanks in advance

  2. #2
    MR bruto's Avatar
    MR bruto is offline Senior Member
    Join Date
    May 2013
    Location
    The Netherlands
    Posts
    130
    Rep Power
    0

    Default Re: Input Error

    IM NOT TOO SURE ABOUT THIS, IM JUST TRYING TO HELP
    i tested it in eclipse, and it seems to get an error in line 12.
    the
    Java Code:
    System.in.read()
    if you use it and check out what .read() actually is you get this:

    Reads the next byte of data from the input stream. The value byte is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.
    A subclass must provide an implementation of this method.


    I don't know if this helped you, but i just tried.

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

    Default Re: Input Error

    Try the nextLine() method instead of the next() method and read the API documentation for the Scanner class and don't just guess what the methods are supposed to do according to your imagination.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  4. #4
    allaudin's Avatar
    allaudin is offline Senior Member
    Join Date
    Apr 2013
    Posts
    271
    Rep Power
    0

Similar Threads

  1. User Input for GUI error message
    By deeevo in forum New To Java
    Replies: 4
    Last Post: 05-24-2013, 09:19 AM
  2. Input Validation Error
    By donewithmytime in forum Advanced Java
    Replies: 1
    Last Post: 01-29-2012, 02:02 PM
  3. input nextLine error
    By scoobyrox in forum New To Java
    Replies: 6
    Last Post: 02-25-2011, 01:08 AM
  4. Input stream error
    By Johnny68 in forum New To Java
    Replies: 10
    Last Post: 08-05-2010, 06:20 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
  •