What does your post have to do with a user typing input into a computer????
Type: Posts; User: Norm
What does your post have to do with a user typing input into a computer????
No user can compete with a computer for speed.
For testing write a simple program with a loop that reads what you type in and prints it on the screen.
Write a test program that times how long each techniques takes.
You're wasting a lot of...
What value does the variable need to have to get into the loop?
Read into a variable and print out the contents of the variable before using the data in the condition of a while loop. You need to see what read() returns.
Add some code to time it.
What do you get in the array when you execute the code?
Have you found any other solutions than what have been posted so far?
Read the String, separate the words, convert the words to int, store the int in the next slot in the array.
What do you mean by "most efficient"?
Fewest lines of java code?
Fastest execution...
There are two parts to this:
Read the input from the user
Store the input into an array.
That is the way it is done. Read a String, convert it to int, store it in the array.
Then the program will be getting Strings.
If you are reading from the keyboard, you can not read integer values. Everything typed in is a character.
How is the data entered for you to read? Is there a person at the keyboard that is entering...
Sorry, where is the problem. You ask the user for the value of N and then read in N values from the user. All the values would have to be separated to be recognized as separate values.
When do you find out the value of 'N'?
If the input record contains more than 'N' values, how will you know when you have enough and can ignore the rest of the values?