Hi, I'm sorry about the last post. I shouldn't just say "I don't get it" as the whole question. It's totally my fault. Anyways, I am having a problem with this code. I get an error no matter what I try. The error I'm getting right now is this:
"error cannot find symbol"
So, here is the code:
public class Item { private int myN; public Item( int n ) { myN = n; } public String toString() { return "Item: " + myN; } public int getN() { return myN; } public static Item[] makeItemArray( int len ) { Item[] a = new Item[ len ]; int i; for ( i = 0 ; i < len ; i++ ) a[ i ] = new Item( i ); return a; } } public class MainClass { public static void main( String[] args ) { //this is the part where I can edit the code: Item[] array = Item.makeItemArray( 10 ); int nEvens = 0; for (Item item : array) for (i = 0; i < array.length - 1; i++){ if (i % 2 == 0){ nEvens++; } } System.out.println( "There are " + nEvens + " evens." ); //that was it } }
I thought I was on the right track with the nested for-loops, but I'm not quite sure.