Question about for loop. 7/13

So, the code came back correctly. But I have a question about it. Where did the ‘j’ in the for loop came from? I don’t get that part.

import java.util.ArrayList;

public class TemperaturesC {
	public static void main(String[] args) {

		ArrayList<Integer> weeklyTemperatures = new ArrayList<Integer>();
		weeklyTemperatures.add(2, 111);

		for (int j = 0; j < weeklyTemperatures.size(); j++) {
     System.out.println( weeklyTemperatures.get(j) );


Well, you defined it - first you declared that initial value of j is 0, than you told us that j must be less than weeklyTemperatures.size, and finally you declared that for loop should add 1 in each iteration.

1 Like

It’s just what you named the temporary variable held inside your loop.
You’ve probably seen it as i or counter, etc etc
It could be named anything. The important part is understanding HOW your for loop does what it does.

1 Like

Thanks! It’s the int j = 0 right? So I could name it anything else?

Yes - it could be i, k,z - whatever you want. :slight_smile:

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.