Question: Java reports a Type mismatch exception when trying to print big numbers and stored an array. 

I'm currently learning some Java. One of the excercises of the course I'm doing, asks me to generate some random numbers and storing them inside an array. Everything works fine as long as I generate integers, I can print them without trouble using out.print.

But, when I generate big numbers and try to print them, Java informs a type mismatch in the line where I have the for each loop. 

```
package clases;

public class Arrays_3 {
    public static void main (String [] args) {
        long [] array_random=new long[150];
        for (int i=0;i<array_random.length;i++) {
            array_random[i]=(long)Math.round(Math.random()*100000) ;
        }

        for (long elemento:array_random) {
            System.out.println(array_random[elemento]);
        }
    }
}

```

This is the error I get on Eclipse console after running the code above:

```none
Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
    Type mismatch: cannot convert from long to int

    at clases.Arrays_3.main(Arrays_3.java:17)

```

Line 17 is where the `System.out.print` method is.

Answer: 
I guess you are trying to print the element. what you are looping is the value(int type) instead of the index(long type). 

```java
      for (long elemento:array_random) {
            System.out.println(elemento);
        }

```
Elemento is a long, while arrays are indexed by integers. 

Besides, with for(long elemento: array) you are creating an iterator that return one value of the array on each iteration of the loop. Thus, you can directly print it.

```
for (long elemento : array) {
    System.out.println(elemento);
}

```

If you want to lookup for an element of the array, you should iterate over an index variable 

```
for (int idx=0;idx<array.length;idx++) {
    System.out.println(array[idx]);
}

```