5/13 Arraylist min. value


#1

Kindly help me with the problem in this code
I tried two codes to see if it works. But none of them worked.

#First Code I tried
import java.util.ArrayList;

public class Temperatures {
	
	public static void main(String[] args) {
    
    ArrayList<Integer> weeklyTemperatures = new ArrayList<Integer>();
    weeklyTemperatures.add(78);
    weeklyTemperatures.add(67);
    weeklyTemperatures.add(89);
    weeklyTemperatures.add(94);
    int a = 0;
    int min = weeklyTemperatures.get(0);
    for(int i = 1; i< weeklyTemperatures.size(); i++)
    {
      if(min > weeklyTemperatures.get(i))
      {
        a = i;
      }
    }
    System.out.println(weeklyTemperatures.get(a)); 
   


	}
}



#Second Code I tried 
import java.util.ArrayList;

public class Temperatures {
	
	public static void main(String[] args) {
    
    ArrayList<Integer> weeklyTemperatures = new ArrayList<Integer>();
    weeklyTemperatures.add(78);
    weeklyTemperatures.add(67);
    weeklyTemperatures.add(89);
    weeklyTemperatures.add(94);
    System.out.println(weeklyTemperatures.get(1));


	}
}


#2

It's a rather poorly made exercise, they require you to match this pattern:
(and many other exercises are also just pattern matching)

/add\(\s*94\s*\)\s*;\s*System\.out\.println\(\s*weeklyTemperatures\.get\(\s*1\s*\)\s*\)\s*;/

Your second looks fairly similar to this pattern, you can compare them closer at regex101.com, insert the pattern and your code and see if they match, if they differ you can delete characters at the end of the pattern until it matches again and you'll have found where the difference starts


#3

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