Advertisement
Guest User

12431241

a guest
May 26th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1.  
  2. public class zadanieCzwarte {
  3. public static void main(String[] args) {
  4. //WPISANIE WARTOŚCI
  5. double[] arr = {3.0, 2.0, 1.0, 6.0, 15.0, 28.0, 70.0};
  6. solution(arr);
  7. }
  8.  
  9.  
  10. public static double[] solution(double[] arr){
  11. double[] results = new double[arr.length];
  12. for (int i=1; arr.length>i; i++){
  13. results[i-1] = sinCalc(arr[i-1]);
  14. }
  15.  
  16. readArr(results);
  17. return results;
  18. }
  19.  
  20. public static void readArr(double[] arr){
  21. for (int i =1; i<arr.length; i++){
  22. System.out.println(arr[i-1]);
  23. }
  24. }
  25.  
  26. public static double formula(double x, int component){
  27. double result = Math.pow(x, component)/silnia(component);
  28. return result;
  29. }
  30.  
  31. public static double sinCalc(double x){
  32. double initialValueOfX = x;
  33. double value = 1;
  34. int checkValue = 1;
  35. for (int i = 3; Math.abs(value) > 0.0001; i=i+2){
  36. if(checkValue % 2 == 0){
  37. x = x + formula(initialValueOfX,i);
  38. } else if(checkValue % 2 != 0) {
  39. x = x - formula(initialValueOfX,i);
  40. }
  41.  
  42. value = formula(initialValueOfX,i);
  43. checkValue++;
  44. }
  45. return x;
  46. }
  47.  
  48. public static double silnia(int number) {
  49. double result = number;
  50. for (int i = number - 1; i > 1; i--) {
  51. result = result * i;
  52. }
  53. return result;
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement