How to calculate the series 1 3 4 8 15 27 50 92 169 311 572 ... N in Java

1 Answer

0 votes
// 1 3 4 8 15 27 50 92 169 311 572 ... N 
  
// (1) (3) (4) : 1 + 3 + 4 (8) : 3 + 4 + 8 (15) : 4 + 8 + 15 (27) :
// 8 + 15 + 27 (50) : 15 + 27 + 50 (92) : 27 + 50 + 92 (169) :
// 50 + 92 + 169 (311) : 92 + 169 + 311 (572)

public class MyClass {
    public static void main(String args[]) {
        int a = 1, b = 3, c = 4, total = 11;
  
        System.out.format("%d %d %d ", a, b, c);
  
        int sum = 0;
        for (int i = 4; i <= total; i++) {
            sum = a + b + c;
            System.out.format("%d ", sum);
  
            a = b;
            b = c;
            c = sum;
        }
    }
}


  
  
/*
run:
  
1 3 4 8 15 27 50 92 169 311 572 

*/

 



answered Mar 30, 2022 by avibootz
...