|
|
|
|
|
|
Re: Any help plz [message #1059769 is a reply to message #1059620] |
Tue, 21 May 2013 14:35 |
|
On 5/21/2013 6:47 AM, Pawel BobTosh wrote:
> Hej,
> i have a similar problem.
> I think (don't know) that there is something wrong. So the scanner
> problem seems to point at a problem in eclipse.
>
> In my case Eclipse give the warning that the scanner has not been close,
> however if i add the 'scanner.close()' function it dont do what it
> suppose to.
> I'm a beginner but the code seems to be right.
> I normaly dont use eclipse and i know that the code works perfectly in
> other programs,
> but not in eclipse. I dont meen the warnings, in eclipse the code just
> crashes and i would like to know why?
>
> so this is the code that do not work in eclipse:
>
>
> import java.util.Scanner;
>
> public class Scan {
>
> public static int reader(){
> int x = 0;
>
> do{
> try
> {
> System.out.print("[E]:");
> Scanner sc = new Scanner(System.in);
> x = sc.nextInt();
> sc.close();
> }
> catch(Exception ex){ System.out.println(ex);x=-1; }
> }while(x<0);
> System.out.println("[ok]");
> return x;
> }
>
> }
>
> If i remove the close() out of the code it works fine with the exception
> of warnings.
If, by "doesn't work in Eclipse", you mean that you can't use the
Console view to type in input, this is true. This program will only work
correctly run outside of Eclipse. The Eclipse console window doesn't
support input.
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03969 seconds