Why does this simple for loop create multiple errors?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Steel546
    New Member
    • Mar 2009
    • 25

    Why does this simple for loop create multiple errors?

    Code:
       public static void main(String[] args) {
    
             double modArray[]= new double[10];
    
             for (int i =1, i < modArray.length(), i++){
                    modArray[i]= (26*i+7)%31;
                    } //end for
            System.out.println(modArray);
        }//end main
    I really don't understand why this creates errors as a simple for loop? Errors such as "i is already defined in java.lang.strin g[]", "; expected", "> expected", and boolean required? Can anyone shed any light on this?
  • jx2
    New Member
    • Feb 2007
    • 228

    #2
    Your syntax is wrong
    line 5 should look :
    Code:
             for (int i =1; i < modArray.length; i++){
    //some code here
    }
    regards
    Jan

    Comment

    • Steel546
      New Member
      • Mar 2009
      • 25

      #3
      Ohhhhhhh.... I feel dumb. There was also some brackets missing in my code as well that contributed to that.

      Comment

      Working...