Defina una clase con un método: acumulate2zero(int z) que calcule la suma acumulada desde z a cero. Realice los controles correspondientes.
Defino el método estatico accumulate2zero(int z) de la clase recurrence.
package certification1;
public class Recurrence {
static int accumulate2zero(int x){
assert(x > 0);
if(x == 1){
x += 0;
}else{
x += accumulate2zero(x-1);
}
return x;
}
}
package certification1;
public class Certification1 {
public static void main(String[] args) {
try{
System.out.println(Recurrence.acumulate2zero(10));
}
catch(Exception e){
System.out.println(e.getMessage());
}
}
}
No comments:
Post a Comment