Advertisement
Guest User

Untitled

a guest
Oct 7th, 2015
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12.  
  13. float x = 9;
  14.  
  15. float result = sqrt(x);
  16.  
  17. System.out.println(result);
  18.  
  19. }
  20.  
  21. public static float sqrt(float x) {
  22. float y = 1;
  23. int two = 2;
  24. float temp1 = 0;
  25. float temp2 = 0;
  26. float z = 0;
  27. while (y != z) {
  28. z = y;
  29. temp1 = x/y;
  30. temp2 = temp1 + y;
  31. y = temp2/two;
  32. }
  33.  
  34. return(y);
  35.  
  36. }
  37.  
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement