Quick question

I need to produce this as an output for part of a program:

Enter number pair 1: 12 16

the user enter the 2 pairs of numbers at the end, my question is: How do I set the program to let me enter 2 pairs on one command, like

System.out.println("Enter a number: ");

n = input.nextInt();

The user would enter 12 16 in one statement.

What is the code for this?

[423 byte] By [eleca] at [2007-10-2 10:59:39]
# 1
Take in a String and parse it into an array of values.%
duffymoa at 2007-7-13 3:28:17 > top of Java-index,Java Essentials,New To Java...
# 2
How would I parse it into 2 different values?
eleca at 2007-7-13 3:28:17 > top of Java-index,Java Essentials,New To Java...
# 3

You could use [url http://java.sun.com/j2se/1.5.0/docs/api/java/util/Scanner.html#nextLine()]Scanner.nextLine()[/url] to get the input string.

With that string, you could use [url http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html#split(java.lang.String)]String.split()[/url] to get your array of separate tokens.

Then to convert each token string into an integer, you could use [url http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Integer.html#parseInt(java.lang.String)]Integer.parseInt()[/url].

Regards

jfbrierea at 2007-7-13 3:28:17 > top of Java-index,Java Essentials,New To Java...