Forums Register Login

Error #: 361 : variable required, but value found

+Pie Number of slices to send: Send
Hi,
if we have the inPut={"A","B","A","C","B"} then we want the non-repeated array with element as outPut={"A","B","C"}

The following code showing the "Error #: 361 : variable required, but value found at line 12, column 34".

Vector inPut=new Vector();
Vector outPut=new Vector();
int m=0;
for(int i=0; i < inPut.size(); i++){

if(inPut.elementAt(i) == null) continue;
else{

for(int j=i+1; j < inPut.size(); j++){

if(inPut.elementAt(i) == inPut.elementAt(j))

// Error Line=12 inPut.elementAt(i) = null;

} // inner for
} // else
outPut.elementAt(m) = inPut.elementAt(i);
System.out.println("OutPut=" +outPut.elementAt(m));
m++;
} // outer for


Kind Regards

Rashid.
rhkhokhar@hotmail.com
+Pie Number of slices to send: Send
Vector implements List I thikn you are doing a lot of work you don't have to. List (and thus vector) has a contains method which will tell you if the vector already contains what you have). for instance if (!output.contains(element)) //add it here

Regarding the original question i'm not sure what to tell you, except you may want to add some code formatting tags to make it easier to read
+Pie Number of slices to send: Send
Couple of things here
1) inPut.elementAt(i) gives you an object that you can't set equal to seomthing if you want to set the value of an object at a particular position in the array do a vector.setElementAt(index, object);

2) The second for loop is not necessary to see if the vector contains the object you are looking for it's easy enough to say outPut.contains(inPut.elementAt(i));

3) The M is not required either as you should be able to just say outPut.add(object) - unless of course you have to maintain the same "number" position in the array for some reason

It sure was nice of your sister to lend us her car. Let's show our appreciation by sharing this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 2029 times.
Similar Threads
where this program goes wrong(using 2D array)?
June Newsletter Puzzle
Extra bytes being read into file.
heres my code
Finding a particular pattern in a file
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 07:21:14.