Results 1 to 2 of 2
  1. #1
    johnny7white is offline Member
    Join Date
    Nov 2007
    Posts
    2
    Rep Power
    0

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    Java Code:
            int n = 10;
            double[] radians = { 0, Math.PI/6, Math.PI/4, Math.PI/3, Math.PI/2 };
            System.out.println("For n = " + n);
            for(int j = 0; j < radians.length; j++) {
                double d = 1.0;
                int sign = -1;
                for(int k = 2; k <= n; k += 2) {
                    d += sign * Math.pow(radians[j], k)/factorial(k);
                    sign *= -1;
                }
                System.out.printf("radians[%d] = %.3f  cos(%4.1f) = %8f  d = %f%n",
                                   j, radians[j], Math.toDegrees(radians[j]),
                                   Math.cos(radians[j]), d);
            }
        }
    
        private static int factorial(int n) {
            if(n == 0)
                return 1;
            return n*factorial(n-1);
        }

Similar Threads

  1. how to write onto a file
    By mirage_87 in forum New To Java
    Replies: 6
    Last Post: 09-08-2009, 04:54 PM
  2. Replies: 0
    Last Post: 04-06-2008, 08:43 PM
  3. need help to write Program in JAVA
    By maneibr in forum New To Java
    Replies: 1
    Last Post: 03-13-2008, 02:28 PM
  4. Replies: 1
    Last Post: 02-15-2008, 05:07 PM
  5. Help with write file in java
    By mathias in forum New To Java
    Replies: 1
    Last Post: 07-31-2007, 07:51 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •