Hi:
I have Java6 intalled.
Using TextPad, I can compile code with java.util.Scanner.nextInt() in it, however, when I try to run the code it error out every time.
The code is:
import java.util.Scanner;
public class ScannerApp
{
static Scanner sc = new Scanner(System.in);
public static void main(String[] args)
{
System.out.print("Enter an integer: ");
int x = sc.nextInt();
System.out.println("You entered " + x + ".");
}
}
The error message is:
Enter an integer: Exception in thread "main" java.util.NoSuchElementException
at java.util.Scanner.throwFor(Scanner.java:838)
at java.util.Scanner.next(Scanner.java:1461)
at java.util.Scanner.nextInt(Scanner.java:2091)
at java.util.Scanner.nextInt(Scanner.java:2050)
at ScannerApp.main(ScannerApp.java:11)
I can compile and run the above code from DOS prompt (command window).
TIA
Code with using util.Scanner.nextInt() complies but not run
Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard
-
- Posts: 3
- Joined: Fri Dec 07, 2007 11:40 pm
-
- Posts: 3
- Joined: Fri Dec 07, 2007 11:40 pm
Those that expect input from STDIN.
Textpad is NOT a Java IDE. If you want a Java IDE, go to www.eclipse.org
Then you can not only run your programs from the IDE, you can even debug them and have many other Java-specific features (like code completion, instant error messages and so on)
Textpad is NOT a Java IDE. If you want a Java IDE, go to www.eclipse.org
Then you can not only run your programs from the IDE, you can even debug them and have many other Java-specific features (like code completion, instant error messages and so on)
-
- Posts: 3
- Joined: Fri Dec 07, 2007 11:40 pm