The objective is trying to create a code that gets the difference of the max and min number of the Array List.
As a beginner I am having trouble understanding why I get that maxRange is not declared in my code.
private int firstElement;
public int maxRange(ArrayList<Integer> arr)
{
if (maxRange.size() ==0)
{
return 0;
}
if (maxRange.size()==1)
{
return 1;
}
int FirstElement = maxRange.get(1);
int max = firstElement;
int min = firstElement;
for ( int i =0; i < maxRange.size(); i++)
{
int elementValue = maxRange.get(i);
if(max < elementValue)
{
max = elementValue;
}
if (elementValue < min)
{
min = elementValue;
}
}
return (max -min) + 1;
}
public class Scratchpad
{
public static void main(String[] args)
{
List <Integer> maxRange = new ArrayList <>();
maxRange.add(3);
maxRange.add(11);
maxRange.add(25);
maxRange.add(48);
System.out.println(maxRange);
}
}