Я работаю над школьным заданием, где мне нужно получить доступ к данным из ArrayList с помощью некоторых методов, которые я написал.
public static void main(String[] args) throws IOException {
String fileName = "USPopulation.txt";
File fileReader = new File(fileName);
ArrayList<Integer> populations = new ArrayList<Integer>();
Scanner inputFile = new Scanner(fileReader);
while (inputFile.hasNext()) {
populations.add(inputFile.nextInt());
}
System.out.println(populations.greatest());
/**
* Receives an ArrayList and returns the index of the value that has the
* greatest increase from the previous value in the collection.
*
* @param populations
* @return greatestI
*/
public static int greatest(ArrayList<Integer> populations) {
int greatestDiff = 0;
int greatestI = 0;
int i = 0;
while (i < populations.size() - 1) {
int tempDiff = populations.get(i + 1) - populations.get(i);
if (tempDiff >= greatestDiff) {
greatestDiff = tempDiff;
greatestI = i + 1;
}
i++;
}
return greatestI;
}
}
Когда я пытаюсь вызвать свой метод, лучше всего, явстретился с ошибкой
Метод great () не определен для типа ArrayList.
Я думал, что нужное мне определение было включено в параметр моего метода, но, видимо, нет.
Сообщения об ошибках и обнаруженные мной неисправности делают его похожим наМне нужно преобразовать ArrayList populations
в тип, с которым методы справляются, но, похоже, ничего из того, что я пробую, не работает.
Цените любую помощь.Спасибо всем, кто нашел время, чтобы помочь новичку.вернуть smalllestI;