Actually, I'm having some trouble now, if there's anyone out there who can help.
The above was working for me what I was using very very simple java programs (I'm just starting to learn, so it was working for the first lesson).
So, when I had my main class with only a method that prints stuff, it was working.
System.out.print("Hello World");
for example.
But now I'm trying something a bit more complicated, and it's not working. And I know it should be working, because it's working from cmd (I'm using win7 64 bit in case that's important)
Here's the code:
- Code: Select all
import java.util.Scanner;
public class Addition
{
//main
public static void main( String[] args)
{
Scanner input = new Scanner( System.in );
int number1;
int number2;
int sum;
System.out.print("Adding numbers --");
System.out.print("Enter first integer: ");
number1 = input.nextInt();
System.out.print("Enter second integer: ");
number2 = input.nextInt();
sum = number1 + number2;
System.out.printf( "Sum is %d\n", sum );
}
}
And here is the error message when I press f7:
- Code: Select all
Adding numbers --
Enter first integer: Exception in thread "main" java.util.NoSuchElementException
at java.util.Scanner.throwFor(Scanner.java:907)
at java.util.Scanner.next(Scanner.java:1530)
at java.util.Scanner.nextInt(Scanner.java:2160)
at java.util.Scanner.nextInt(Scanner.java:2119)
at Addition.main(Addition.java:19)
[Finished in 1.1s with exit code 1]
So, looks like it's having trouble with importing Scanner input or something...dunno.
Anybody have an idea of what's going on and how to fix it?
For the record, it's apparently building it correctly, just not running it correctly.