public class SumOfContinuousNatural {
public static void main(String[] args) {
for (int i = 1; i <= 20; i++) {
fx(i);
}
}
public static void fx(int n){
Stack<String> stack = new Stack<>();
for (int j = 1; j <= n; j++) {
int sum = 0;
String str = "";
int i = j;
while (i <= n){
sum += i;
str += i + "+";
if(sum == n){
str = n + "=" + str.substring(0,str.length() - 1);
stack.push(str);
}
if(sum > n){
break;
}
i ++;
}
}
int size = stack.size();
while (!stack.isEmpty()){
System.out.println(stack.pop());
}
System.out.println("Result:" + size);
}
}