Blue Bridge cup-Sine dance of basic exercises

Source: Internet
Author: User

Problem description FJ recently opened a mathematical analysis course for his cows. FJ knows that to learn this course well, there must be a good basic function of trigonometric function. So he is going to play a "Sine Dance" game with the cows to improve their computing power.
You may wish to set
An = sin (1-sin (2 + sin (3-sin (4 +... sin (n ))...)
Sn = (... (A1 + n) A2 + N-1) A3 +... + 2) An + 1
FJ wants the cows to calculate the Sn value. Please help FJ print the complete Sn expression to help the cows solve the problem easily. The input format is N <201. In the output format, output the corresponding expression Sn, ending with a line break. No extra spaces, line breaks, or carriage returns are allowed in the output. Sample input 3 sample output (sin (1) + 3) sin (1-sin (2) + 2) sin (1-sin (2 + sin (3) + 1

import java.util.Scanner;public class Main{/** * @param args */public static void main(String[] args) {// TODO Auto-generated method stubScanner scanner=new Scanner(System.in);System.out.println(s(Integer.parseInt(scanner.nextLine()), 1));//System.out.print(sin(3, 1));}static String s(int n,int i){if(i==n){return ""+An(n)+"+"+(n-i+1);}else {return "("+An(i)+"+"+(n-i+1)+")"+""+s(n, i+1)+"";}}static String An(int n){return sin(n, 1);}static String sin(int n,int i){if(i==n){return "sin("+n+")";}else {if(i%2==0)return "sin("+i+"+"+sin(n, i+1)+")";//(int)Math.pow(-1,i)else {return "sin("+i+"-"+sin(n, i+1)+")";}}}}



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.