Exercise 7 not working/whats wrong?


#1

Hello, i'm stuck on exercise 7, i wrote it all perfectly, but it keeps giving me the following error:

TemperaturesC.java:13: error: cannot find symbol
     for (int j = 0; i < weeklyTemperatures.size(); j++) {
                     ^
  symbol:   variable i
  location: class TemperaturesC
1 error

My code so far is:

import java.util.ArrayList;

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

		ArrayList<Integer> weeklyTemperatures = new ArrayList<Integer>();
		weeklyTemperatures.add(78);
		weeklyTemperatures.add(67);
		weeklyTemperatures.add(89);
		weeklyTemperatures.add(94);
		weeklyTemperatures.add(2, 111);
    for (int j = 0; i < weeklyTemperatures.size(); j++) {
  System.out.println( weeklyTemperatures.get(j) );
}
    
    
	}
}

Thanks in advance.


#2

Your error message is telling you that you have told Java to do something with a variable called i but i has not been defined. Why did you choose i < weeklyTemperatures.size() as the condition for ending your for loop?


#3

Well ■■■■ me. Didn't notice that, it was the only thing keeping the code from working.

Its been a while since i've worked with programming, gotta brush up my reading/perception skills again.


#4

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