1 import java.util.Scanner; 2 3 public class Main{ 4 public static void main(String[] args) { 5 Scanner input = new Scanner(System.in); 6 int n; 7 n = input.nextInt(); 8 String An=""; 9 String Sn=""; 10 for(int i=1;i<=n;i++){ 11 if(i!=n) 12 Sn = "("+Sn+An(i)+"+"+(n-i+1)+")"; 13 if(i==n) 14 Sn = Sn+An(i)+"+"+(n-i+1); 15 } 16 System.out.println(Sn); 17 } 18 public static String An(int n){ 19 String An = ""; 20 char temp; 21 for(int i=n;i>=1;i--){ 22 if(i%2==0) 23 temp = ‘+‘; 24 else 25 temp = ‘-‘; 26 if(i!=n) 27 An = "sin("+i+temp+An+")"; 28 if(i==n) 29 An = "sin("+i+")"; 30 } 31 return An; 32 } 33 34 }
原文:http://www.cnblogs.com/lolybj/p/6498105.html