public static void main(String[] args) {
int minKmh = 10;
int maxKmh = 20;
int step = 5;
String allSpeeds = "";
while (minKmh <= maxKmh) {
allSpeeds += minKmh + ",";
minKmh += step;
}
String[] allSpeedsAsArray = removeLastChar(allSpeeds).split(","); // result: 10,15,20
}
private static String removeLastChar(String str) {
return str.substring(0, str.length() - 1);
}
I have a minimum car speed and a maximum car speed. In this case 10 and 20. And I want every speed which is between minimum and maximum where the speed gets incremented by a step speed.
I don't like my current version because it is large in my opinion. Is it possible to shorten the code to 1-2 liner?