fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. Scanner sc = new Scanner(System.in);
  13. int n;
  14. double x;
  15. n = sc.nextInt();
  16. x = sc.nextInt();
  17. double result=0;
  18. for(int i = n; i > 0; i--){
  19. int j = 1;
  20. if((i%2)==0) j = -1;
  21. result += j * Math.sin(i * x) / i;
  22. }
  23. System.out.println(result);
  24. }
  25. }
Success #stdin #stdout 0.06s 711680KB
stdin
3 2
stdout
1.194560175080004