I don't know if any of you guys have used Netbeans or Java Studio Creator, but I'm experimenting with both. I've got this program that inputs two integers, computes the sum, and displays the result:
public class HelloWorld
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
int x;
int y;
System.out.println("Enter a value for x: ");
x = input.nextInt();
System.out.println("Enter a value for y: ");
y = input.nextInt();
int sum = x + y;
System.out.println("The sum is: " + sum);
}
}
What I can't figure out is every time I re-run the program, the previous integer is still sitting in the input box. Let's say I run the program and the first integer I enter is 3. Then I hit the Enter key to send it along. Then for thte second integer I hit 9. Then I hit the Enter key to send it along. The program displays 12 and I'm done.
Now I want to run the program again, and when I hit the Run button, the number 9 is still sitting in the input box. This is quite annoying. It shouldn't be there. Seems to me when you re-run the program the box should be clear, ready to accept new input.
By the way, this is not a GUI program, this is a console program. But there is a long input box on the bottom of the IDE window when you write a program that uses a scanner to get input from the keyboard.