This week's book giveaways are in the iOS and Features new in Java 8 forums. We're giving away four copies each of Barcodes with iOS: Bringing together the digital and physical worlds and Core Java for the Impatient and have the authors on-line! See this thread and this one for details.
I don't know what you mean by "add a value" -- int addition, assignment, etc... But it seems to me you have an int array and a String, so you need to convert that String into an int. I wonder if java.lang.Integer has any methods that might help (hint, hint)...
There is no emoticon for what I am feeling!
Joined: Oct 19, 2005
i want to prompt the user for a value and then add that to an array and then print out all the values at the end that are in the array..
ignore the string bit because im not sure that is the best way of doing it..
Joined: Sep 16, 2005
You still haven't defined "add that to an array": 1. Append a new value into an array, incrementing its size by one? 2. Take that number and add that to the value already held at a certain offset? 3. Store that number at a certain offset, overwriting what was there before?
If you mean: making the array longer by one element and assigning the entered value to the new element, it's not going to work with a regular array.
Arrays in Java have a fixed length. If you need a variable length list of numbers, you should use the collection classes, such as ArrayList (which is already imported in your program, but you're not using it yet!).
Use Integer.parseInt(myString) to convert the string to an integer which then you can assign to your array. Here however it is important that the data input by the user is an integer, otherwise your method will throw a NumberFormatException