Reputation: 86627
Is it possible to somehow shorten many if-expressions? Example: imagine 3 numbers, and each will only count up if the former one reached count of 10.
int a = 0, b = 0, c = 0;
a++;
if (a == 10) {
a = 0;
b++;
if (b == 10) {
b = 0;
c++;
}
}
return toString(a+b+c); //I know this is not valid
Is it possible to somehow shorten these kind of expressions?
Upvotes: 0
Views: 98
Reputation: 16736
Syntax-wise, no. Not in Java. Your only way to do that is to improve your algorithm. I am not sure exactly what your algorithm is trying to achieve, but by the looks of it, you could reduce nesting by proper usage of collections.
Upvotes: 2