Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main1 {
- public static void main(String[] args){
- int kolvo = 0;
- double pi;
- int i = 0;
- while (kolvo < 1000) {
- Point point = new Point();
- point.random();
- if(point.checkInCircle()) {
- i ++;
- }
- pi = i / 1000 * 4;
- System.out.println("Число пи = " + pi);
- kolvo++;
- }
- }
- }
- class Point{
- private double x;
- private double y;
- public void random(){
- x = Math.random();
- y = Math.random();
- }
- public boolean checkInCircle() {
- if (this.x * this.x + this.y * this.y < 1) {
- return true;
- }else{
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement