Entering values in an Array

Think of this scenario.I want to create a window that will ask the user to enter a value(string).That value(string) will be parsed and it will be entered as an integer in the array(using a loop).I don't know how to make the loop.Can someone help me?
[264 byte] By [fde_cpua] at [2007-11-27 4:54:13]
# 1
Integer.parseInt(String) will do the conversion from String to int.Kaj
kajbja at 2007-7-12 10:08:49 > top of Java-index,Java Essentials,New To Java...
# 2
I know that,but I don't know how to make the loop
fde_cpua at 2007-7-12 10:08:49 > top of Java-index,Java Essentials,New To Java...
# 3
You do know how to create a loop?Kaj
kajbja at 2007-7-12 10:08:49 > top of Java-index,Java Essentials,New To Java...
# 4
Yes,I know
fde_cpua at 2007-7-12 10:08:49 > top of Java-index,Java Essentials,New To Java...
# 5
> Yes,I knowSo what is the problem in that case?You know how to convert from string to int, you know how to create a loop, and I guess you know how to create an array?
kajbja at 2007-7-12 10:08:49 > top of Java-index,Java Essentials,New To Java...
# 6

Here is my code....it seams that "i" sticks to 0...I don't know why but "i" doesn't seam to increment.Maybe you can tell me why.

for(int i=0;i<numere.length;i++){

if( sursa == ok){

raspuns = text.getText();

numere=Integer.parseInt(raspuns);

System.out.println(" Elementul de pe pozitia "+ i + " este " + raspuns + " " );

break;

}}>

fde_cpua at 2007-7-12 10:08:49 > top of Java-index,Java Essentials,New To Java...
# 7
Why do you have a break there? That will exit the loop.Kaj
kajbja at 2007-7-12 10:08:49 > top of Java-index,Java Essentials,New To Java...
# 8
Well if I delete the break it will initiate all the array's values with the one that I enter every time.....but if I put the break the "i" will not increment....so it's the same....not working properly
fde_cpua at 2007-7-12 10:08:49 > top of Java-index,Java Essentials,New To Java...
# 9

> Well if I delete the break it will initiate all the

> array's values with the one that I enter every

> time.....but if I put the break the "i" will not

> increment....so it's the same....not working properly

What? Of course it isn't working as long as you have that break there. You are exiting the loop.

kajbja at 2007-7-12 10:08:49 > top of Java-index,Java Essentials,New To Java...
# 10
Well if I delete the break command, all the array's elements will have the same value.For example if I enter 5 ,the array will look like this(5 5 5 5 and so on )
fde_cpua at 2007-7-12 10:08:49 > top of Java-index,Java Essentials,New To Java...
# 11

> Well if I delete the break command, all the array's

> elements will have the same value.For example if I

> enter 5 ,the array will look like this(5 5 5 5 and so

> on )

Then you have to rethink your design. It is obviously broken. If you don't want to loop through all values and fill all values, then don't use a loop. But using a loop with "break" is pointless.

petes1234a at 2007-7-12 10:08:49 > top of Java-index,Java Essentials,New To Java...
# 12
> Then you have to rethink your design. It is> obviously broken. That's why I asked for help
fde_cpua at 2007-7-12 10:08:49 > top of Java-index,Java Essentials,New To Java...
# 13

> > Then you have to rethink your design. It is

> > obviously broken.

> That's why I asked for help

Again, this is more than just fixing a for-loop. You need to rethink your design, and only you know the full requirements. I don't think we can or should do that for you.

Good luck.

petes1234a at 2007-7-12 10:08:49 > top of Java-index,Java Essentials,New To Java...
# 14
raspuns = text.getText();You have the above line of code in your for loop. So it reads that value and never allows the user to change the value in the textfield.
floundera at 2007-7-12 10:08:49 > top of Java-index,Java Essentials,New To Java...