Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- (Use trigonometric methods) Print the following table to display the sin value and
- cos value of degrees from 0 to 360 with increments of 10 degrees. Round the
- value to keep four digits after the decimal point.
- Degree Sin Cos
- 0 0.0000 1.0000
- 10 0.1736 0.9848
- ...
- 350 -0.1736 0.9848
- 360 0.0000 1.0000
- */
- public class Exercise520 {
- public static void main(String[] args) {
- System.out.println("\n Degree Sine Cosine");
- System.out.println("________________________________");
- int i=0;
- System.out.print(" "+i+" ");
- System.out.printf("%-6.4f ",sine(i));
- System.out.printf("%-6.4f\n", cosine(i));
- for(i=10; i<=90; i++) {
- System.out.print(" "+i+" ");
- System.out.printf("%-6.4f ",sine(i));
- System.out.printf("%-6.4f\n", cosine(i));
- i = i+9;
- }
- for(i=100; i<=180; i++) {
- System.out.print(" "+i+" ");
- System.out.printf("%-6.4f ",sine(i));
- System.out.printf("%-6.4f\n", cosine(i));
- i = i+9;
- }
- for(i=190; i<=270; i++) {
- System.out.print(" "+i+" ");
- System.out.printf("%-6.4f ",sine(i));
- System.out.printf("%-6.4f\n", cosine(i));
- i = i+9;
- }
- for(i=280; i<=360; i++) {
- System.out.print(" "+i+" ");
- System.out.printf("%-6.4f ",sine(i));
- System.out.printf("%-6.4f\n", cosine(i));
- i = i+9;
- }
- }
- public static double sine(double i) {
- double sinAngle = Math.sin(i/180*Math.PI);
- return sinAngle;
- }
- public static double cosine(double i) {
- double cosAngle = Math.cos(i/180*Math.PI);
- return cosAngle;
- }
- }
Add Comment
Please, Sign In to add comment