int test = numbers.length;

    if (numbers[i] = test)
        {
    }

i want to find the last array in numbers then do something
with it for example out put it the above code is my attepmtp at it
however i am doingd something wrong and cant for the life of me figure out what it is.

Edited 3 Years Ago by Nick Evan: Fixed formatting

Consider that numbers.length returns 5. That stands for

numbers[0]
numbers[1]
numbers[2]
numbers[3]
numbers[4]

Is this enough or you want other explanation?

int test = numbers.length;

if (numbers = test)
{
}

i want to find the last array in numbers then do something
with it for example out put it the above code is my attepmtp at it
however i am doingd something wrong and cant for the life of me figure out what it is.

yeah you need to change the code, you don't need to loop over the array.

int test = numbers.length;
    
/*temporary variable with same type as numbers */  = numbers[test-1];

This will give you last member of the array to the temporary variable. Then do what you want to do with it.

Sorry i was not very clear in what my problem is for example i

i am currently reading the values of the array in a loop then
chaning a string based upon that
what i want to do is once it comes to the last element in the array
test =numbers.lenght i want it to do something specefic

for (int i = 0; i < numbers.length; i++)
{
    if (numbers.length >1)
        {
   replacement = replacement.append(numbers[i]+",");    // need to insert comma after number to send in bulk
   }
    else
replacement = replacement.append(numbers[i]+","); 

if (numbers[i] = int test)
{

  replacement = replacement.append(numbers[i]); 
    
        
    
    }
    // if only one number is seleceted then no comma is needed








    


}

Basically once it gets to the final array i dont want it to add a comma.
thanks for the help so far

for (int i = 0; i < numbers.length; i++)
{
    if (numbers.length >1)
        {
   replacement = replacement.append(numbers[i]+",");    // need to insert comma after number to send in bulk
   }
    else
replacement = replacement.append(numbers[i]+","); 

if (numbers[i] = int test)
{

  replacement = replacement.append(numbers[i]);        
    
    }
    // if only one number is seleceted then no comma is needed  


}

Logic of the above for loop is completely of the hook
Can be done simply as

for (int i = 0; i < numbers.length; i++)
{
    if (i+1 == numbers.length){
        //DO SOMETHING SPECIAL LIKE PLACE A QUESTION MARK AT THE END
        replacement = replacement.append(numbers[i]+"?");
    }
    else{
        replacement = replacement.append(numbers[i]+",");    
   }
}

replace that code section in "if" statement with what ever you need to do at that point...

This question has already been answered. Start a new discussion instead.