Close Scanner
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Close Scanner

  1. #1
    Join Date
    Dec 2013
    Posts
    4

    Close Scanner

    Hello, I've been going through a tutorial and have copied some code from it, It give's me an error prompt (well not error, the program still runs, more of a suggestion I guess...) telling me to close the scanner, yet in the code that I've copied there's nothing on the left of his screen... Im a bit confused why this is.

    here's the code in my Eclipse ;



    here's the code in his without the little error thing on the left



    My program does the expected (asks for number then ends when the right one is given) but it has that little prompt on it.

    If anyone could shed some light that'd be great.

    Cheers

  2. #2
    Join Date
    Jun 1999
    Location
    SW Missouri
    Posts
    3,448

    Re: Close Scanner

    Could you post here the error messages and code you are asking about? Not images because text can't be copied from images for including in answers.
    Norm

  3. #3
    Join Date
    Dec 2013
    Posts
    4

    Re: Close Scanner

    Cheers Norm - should be able to get at my computer later and I'll post it up.

  4. #4
    Join Date
    Dec 2013
    Posts
    14

    Re: Close Scanner

    At eclipse, it probably asks you to close the scanner after you are done listening the console.

    It is always good practise to close inputstream once you are done getting input when reading file, reading socket or reading a console. It costs extra threads, blocks further processing and causing hard to find bugs in the application not to close streams.

    Eclipse's warning is probably about this.

    I am not sure about the syntax but scanner.close(); is what you should do once you get what you are looking for.

  5. #5
    Join Date
    Dec 2013
    Posts
    4

    Re: Close Scanner

    Sorry I forgot about this post - here is the code that I wrote though with the error on line 7 :

    Code:
    import java.util.Scanner;
    
    public class ScannerClass {
    	public static void main(String[] args) {
    
    		//Create scanner object
    		Scanner input = new Scanner (System.in);
    
    		//Output the prompt
    		System.out.println("Enter some text:");
    
    		//Wait for the user to enter something
    		
    		short Character = input.nextShort();
    		
    
    		//Tell them what they say
    		System.out.println("You entered : " + Character);
    		
    		
    		
    
    	}
    }

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center