解题思路:
参考代码:
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); //输入一个数N,N<=201 int N = scanner.nextInt(); //A1 = sin(1) //A2 = sin(1-sin(2)) //A3 = sin(1-sin(2 + sin(3))) //A4 = sin(1-sin(2 + sin(3 - sin(4)))) //..An = sin(1-sin(2 + sin(3 - sin(4 + ..sin(n))))) //S1 = A1 + 1 //S2 = (A1 + 2)A2 + 1 //S3 = ((A1 + 3)A2 + 2)A3 + 1.... for (int i = 1; i <= N; i++) { String an = getAn(i); StringBuffer sn = getSn(i, i); if (i == N) { System.out.println(sn); } } } //获取N //根据N计算An,Sn //需要返回值 public static String getAn(int n) { if (n == 1) { return "sin(1)"; } if (n % 2 != 0) { return getAn(n - 1).substring(0, getAn(n - 1).length() - n+1) + "+sin(" + n + ")".repeat(n); }else { return getAn(n - 1).substring(0, getAn(n - 1).length() - n+1) + "-sin(" + n + ")".repeat(n); } } //获取Sn public static StringBuffer getSn(int n,int an) { StringBuffer sb = new StringBuffer(); if (n == 1) { sb.append(getAn(1)).append("+" + (an)); }else { sb.append("(").append(getSn(n - 1, an)).append(")").append(getAn(n)).append("+" + (an-n+1)); } return sb; } }
0.0分
1 人评分
矩阵乘法 (C++代码)浏览:1662 |
多输入输出练习1 (C语言代码)浏览:1219 |
C语言程序设计教程(第三版)课后习题5.7 (Java代码)浏览:910 |
WU-图形输出 (C++代码)浏览:836 |
蚂蚁感冒 (C语言代码)浏览:1408 |
陶陶摘苹果2 (C语言代码)浏览:650 |
C语言训练-大、小写问题 (C语言代码)浏览:719 |
C语言程序设计教程(第三版)课后习题7.3 (C语言代码)浏览:420 |
C语言程序设计教程(第三版)课后习题8.8 (C语言代码)浏览:751 |
C语言程序设计教程(第三版)课后习题8.6 (C语言代码)浏览:854 |