Java tutorial
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.Collections; public class Main { private static ArrayList<Double> exactRatios = new ArrayList<>(); private static ArrayList<Double> getExactRatios(int motorTeeth, int[] wheelTeeth) { exactRatios.clear(); for (int tooth : wheelTeeth) { exactRatios.add((double) tooth / (double) motorTeeth); } Collections.sort(exactRatios); // sort ascending Collections.reverse(exactRatios); // reverse to sort descending // now the zeroth element contains the highest gear ratio i.e. the lowest gear index return exactRatios; } }