Results 1 to 2 of 2
Thread: How do i write this in java...?
- 11-28-2007, 12:43 PM #1
Member
- Join Date
- Nov 2007
- Posts
- 2
- Rep Power
- 0
- 11-28-2007, 07:05 PM #2
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
-
how to write onto a file
By mirage_87 in forum New To JavaReplies: 6Last Post: 09-08-2009, 03:54 PM -
How to write a java bean class object to XML file
By Java Tip in forum java.ioReplies: 1Last Post: 01-29-2009, 09:35 AM -
need help to write Program in JAVA
By maneibr in forum New To JavaReplies: 1Last Post: 03-13-2008, 01:28 PM -
How to write a JAVA program to mesure ping delay..?
By sacr83 in forum NetworkingReplies: 1Last Post: 02-15-2008, 04:07 PM -
Help with write file in java
By mathias in forum New To JavaReplies: 1Last Post: 07-31-2007, 06:51 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks