You can declare multiple variables of the same type in a for-loop:
public static int seven_sum(int num) {
int sum = 0;
for (int i = 7, iterations = 0; iterations < (number of iterations); i = i * 10 + i, iterations++) {
sum = sum + i;
}
return sum;
}
solved Stop a loop after a certain amount of iterations, instead of when a max value is met