first of all, the IM.readString() will give u a compilation error as IM is not defined anywhere in the code. Assuming that u have declared it correctly and reading the string appropriately... here goes some points...
1. Lets say, we have only 3 numbers in the string that is being read. String = "123". But the array is of size 5. So remaining 2 allocated space is waste of space. In this case, we can use array list and finally trim the arraylist to the exact size.
2. Are you sure that the string being read are only numbers? Else, u may get number format Exception when u do the parseInt stuff.
3. Why is it that u are doing "if(markedElement != noah[i])" after setting markedElement to noah. Because, as per ur logic, in the createArray, elements, elements...elements are all set to the string available in the variable number. So the if loop does not make sense as the control will never enter the if loop, unless the marked element is given some different value other than noah elements.
Suggestions & Corrections for this reply is always welcome as everybody is bound to make mistakes.
Joined: Dec 05, 2005
thanks Sriram for your reply:
as per ....
1. yes for now i'm limiting the scope of the strings to be read in to integers only first of all.
2. the "if(markedElement != noah[i])" is a way of checking when the next element DIFFERENT from the first marked element occours. If you noticed: when the markedElement == noah[i] my counter is increased by one,....thereby providing a means by which to count the marked element (i.e. the != operator tells the programme when to stop counting the markedElement and move on to the next one)...in any case it's working, this wasnt my problem. I'm trying to implement an ArrayList....how do i do this?
PS: the IM class is one that reads from the command line (i didnt bother posting it because i thought it would be self explanatory.)