java <identifier> expected

Associate
Joined
19 Jul 2006
Posts
1,847
Im trying to build up a number testing system that takes a number array and goes through to se if th e number is above 0
the if statement is causing a problem and i dunno why


Code:
 public boolean isValidnumber()
   {
      
      boolean numberTest;
     
      numberTest = true; 
      
      for (int i =0;i<number.length;i++)
         
      {
      if((number.[i])<0)  // this is causing a <identifier> expected error
       {
        numberTest = false;
        }
     
      }
      return numberTest;
   }
 
Code:
if([COLOR="Red"](number.[i])[/COLOR]<0)
should be:
Code:
if([COLOR="Red"]number[i][/COLOR]<0)

IF the purpose of your code is to check weather a number in an array of integers is less than zero (negative) then there is another way of writing it.

Code:
public boolean isValidnumber()
{ 
	for (int i : number)
	{
		if (i < 0)
		{
			return false;
		}
	}
return true;
}
 
Back
Top Bottom