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();
}
}
;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();
}
}