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]);
Re: create incremented variable by how passes you take 80 80

"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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.