Lo que pasa es que necesito hacer un programa con recurcividad que me sume n veces seno de n por ejemplo el usuario pide que sea asta 5 y muestre sin(1) luego el sin(1)+sin(2) y luego el resultado +sin(3) y así asta el 5.
este es el código que llevo:
import javax.swing.*;
public class Serie {
public static Double getSeno(Double n) {
if (n <= 1) return Math.sin(n);
else return getSeno(Math.sin(n)) + getSeno((n-1));
}
public static void main(String[] args) {
String ope = JOptionPane.showInputDialog("¿asta donde quieres continuar la serie?");
Double n = Double.parseDouble(ope);
for (Double i =1.0; i <= n; i++){
JOptionPane.showMessageDialog(null," " + getSeno(i));
}
}
}
P. NO QUIERO QUE ME LO HAGAN SOLO QUE ME INDIQUEN EL ERROR.
este es el código que llevo:
import javax.swing.*;
public class Serie {
public static Double getSeno(Double n) {
if (n <= 1) return Math.sin(n);
else return getSeno(Math.sin(n)) + getSeno((n-1));
}
public static void main(String[] args) {
String ope = JOptionPane.showInputDialog("¿asta donde quieres continuar la serie?");
Double n = Double.parseDouble(ope);
for (Double i =1.0; i <= n; i++){
JOptionPane.showMessageDialog(null," " + getSeno(i));
}
}
}
P. NO QUIERO QUE ME LO HAGAN SOLO QUE ME INDIQUEN EL ERROR.