Advertisement
Guest User

Untitled

a guest
Sep 30th, 2014
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.49 KB | None | 0 0
  1. package projects;
  2. import java.lang.Math;
  3. import java.text.DecimalFormat;
  4.  
  5. public class p4 {
  6.     public static void main(String[] args) {
  7.         //declare formatting to fix floating point issue, declare count to count lines for breaks
  8.         DecimalFormat form = new DecimalFormat("#.#");
  9.         int count = 0;
  10.         //print heading using tabs
  11.         System.out.print("Angle \t Sin \t Cos \t Tan \n");
  12.         System.out.print("----- \t --- \t --- \t --- \n");
  13.        
  14.         //start loop for degrees in 0.1 increments
  15.         for(double i=0; i<=180; i=i + 0.1){
  16.             //print degree formatted to #.#
  17.             System.out.print(form.format(i) + "\t");
  18.             //convert i from degrees to radians in variable j, assign sin, cos, and tav values
  19.             double j = Math.toRadians(i);
  20.             double sinValue = Math.sin(j);
  21.             double cosValue = Math.cos(j);
  22.             double tanValue = Math.tan(j);
  23.             //print the rounded values with tabbing
  24.             System.out.print(roundMethod(sinValue) + "\t" + roundMethod(cosValue) + "\t" +  roundMethod(tanValue) + "\n" );
  25.             //count each line, printing a new line every 5
  26.             count++;
  27.             if (count == 5){
  28.                 System.out.print("\n");
  29.                 count = 0;
  30.             }
  31.         }
  32.     }
  33.     //method to round the sin, cos, and tan values, use 10000 for 4 decimal places
  34.     static double roundMethod ( double numberToRound){
  35.         int round = (int)(numberToRound * 10000 + 0.5);
  36.         double roundedValue = (double)round / 10000;
  37.         return roundedValue;
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement