I would like to create an incremented variable by how many passes I go through my for loop. This is what I was thinking. I would like my variable to total with the pass number at the end. So the first pass would be total0, followed by total1, total2, total3, total4. What would you have to do to make the value usuable in the rest of your class? I noticed it would not work outside my for loop.

    int[] array = new int[]{11, 8, 7, 6, 5};
    int[] anArray = new int[100];
    //int[] array = null;
    int total = 0;
    int x = 0;

        for (int i = 0; i < 5; i++)
            //System.out.println("The values in the array ");
            anArray[i] = array[i]; 
            int totali = array[i];
            System.out.println("totali " + totali);
        System.out.println("totali " + totali);
        System.out.println("The length of the array is " + anArray.length);
        for (int i = 0; i < anArray.length; i++)
            if(anArray[i] != 0)
                System.out.println("The values in the array " + anArray[i]);
5 Years
Discussion Span
Last Post by stultuske

"totali " will print exactly that. you'll need to print the value of the primitive int i, not the letter i.
"total" + i should do the trick.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.