Can anybody out there let me know whether, and if so how, Scanner can be used in the Greenfoot environment to receive keyboard input? I am seriously considering using Greenfoot to teach OOP and Java and would like to build a small bank of simple I/O examples first.
The following simple example does not work as intended. Sometimes it hangs (I'm thinking on the line that instantiates the class). Sometimes it prompts for a number and then hangs.
Any help would be appreciated.
import java.util.Scanner;
import java.lang.System;
/**
* Write a description of class Main here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Main
{
/**
* Constructor for objects of class Main
*/
public Main()
{
Scanner input = new Scanner( System.in );
System.out.println("Enter a number");
int n1 = input.nextInt();
System.out.printf("Number is %d\n", n1);
}
}
