ant testing programme interactively

N

newbie_tw

I wrote a simple programme which would accept user input through
;System.in' by Scanner class. However I find out that if I use ant to
test my programme (after packaing those class into a jar file and use
ant task 'java jar' task to run the programme). The ant would not stop
to ask user to input from key board. So the screen would issue error
like
==== error
Exception in thread "main" java.util.NoSuchElementException
at java.util.Scanner.throwFor(Scanner.java:817)
at java.util.Scanner.next(Scanner.java:1431)
at java.util.Scanner.nextInt(Scanner.java:2040)
at java.util.Scanner.nextInt(Scanner.java:2000)
at UserInput.main(Unknown Source)

====



What should I do in order to let ant stop a while and ask user to input
some values?

==== programme to test ====
import java.util.*;
public class UserInput{
public static void main(String[] args) throws Exception{
int a, b;
Scanner scanner = new Scanner(System.in);
System.out.println("Please input integer: a ...");
a = scanner.nextInt();
System.out.println("Please input integer: b ...");
b = scanner.nextInt();
System.out.println("Now the system would sum up data
....");
System.out.println("Summed up result is "+(a*b));
scanner.close();
}

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,113
Latest member
Vinay KumarNevatia
Top