Advertisement
Guest User

Untitled

a guest
Sep 20th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. public class Main1 {
  2. public static void main(String[] args){
  3. int kolvo = 0;
  4. double pi;
  5. int i = 0;
  6. while (kolvo < 1000) {
  7. Point point = new Point();
  8. point.random();
  9. if(point.checkInCircle()) {
  10. i ++;
  11. }
  12. pi = i / 1000 * 4;
  13. System.out.println("Число пи = " + pi);
  14. kolvo++;
  15. }
  16. }
  17. }
  18.  
  19. class Point{
  20. private double x;
  21. private double y;
  22.  
  23. public void random(){
  24. x = Math.random();
  25. y = Math.random();
  26. }
  27.  
  28. public boolean checkInCircle() {
  29. if (this.x * this.x + this.y * this.y < 1) {
  30. return true;
  31. }else{
  32. return false;
  33. }
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement