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]

Integer.parseInt(String) will do the conversion from String to int.Kaj
kajbja at 2007-7-12 10:08:49 >

I know that,but I don't know how to make the loop
You do know how to create a loop?Kaj
kajbja at 2007-7-12 10:08:49 >

> 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 >

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;
}}>
Why do you have a break there? That will exit the loop.Kaj
kajbja at 2007-7-12 10:08:49 >

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
> 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 >

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 )
> 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.
> Then you have to rethink your design. It is> obviously broken. That's why I asked for help
> > 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.
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.