title: Using the Pythagorean theorem with Java
body: <p>I'm trying to create this program that essentially solves the 3rd value of a right triangle. </p>
  
  <p>So the hypotenuse will always be 1, and one of the values (lets call it 'x') will be greater than or equal to -1 but less than or equal to 1.</p>
  
  <p>First, I created a loop to include all values of x:</p>
  
  <pre><code>   int i = 10;
  
     while (i &gt;= -10)
     {
         double x = i / 10.0;
         i--;
  
         System.out.println(x);
  
      } 
  </code></pre>
  
  <p>Now, I get a nice list that gives me the values for x. I now need to use that to calculate the values of the third length of the triangle. I can do this using the Pythagoras Theorem. Here it is:</p>
  
  <pre><code>double firsty = Math.pow(1, 2) - Math.pow(x, 2);
  double y = Math.sqrt(firsty);
  </code></pre>
  
  <p>When I put this in the while loop and then write a print statement for y, the results are formatted in a way that lists the first value of x, then the first value of y, then the second value of x, and then the second value of y. How can I change the formatting so that it just has two separate rows, one column that has the values of x and another column that has the values of y?</p>
  
  <p>What I tried doing originally is using an array to hold the values of x in, but I can't calculate the values of the 3rd length by using an array without getting the compiler to yell 'ERROR' at me!</p>
  
  <p>Using the printf function is what needs to be done (pretty sure), but I get a error message when I use printf for the output of x and y.</p>