1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package com.company;
import java.time.LocalDate;
import java.time.Month;


import static java.time.temporal.ChronoUnit.DAYS;

public class Main {

    public static void main(String[] args) {
	//
//Crear un programa que sume números así:
//
//Dado n=10, debe sumar: 10+7+4+1=22
        int suma=0;
        int n=10;
        while (n>0)
        {
            suma=suma+n;
            n=n-3;
        }
        System.out.println(suma);
        System.out.println(suma(10));

    }
    public static int suma(int n)
    {
        if(n<=0)
        {
            return 0;
        }
        return n + suma(n-3);
    }

}