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);
}
So I have a minimum car speed and a maxmaximum car speed. In this case 10 and 20. And I want every speed which is between minminimum and maxmaximum where minthe speed gets always incremented by a step speed.
I dont'tdon't like my current version because it is large in my opinion. Is it posibblepossible to shorten the code to 1-2 liner?