Skip to content

Commit 559cc7d

Browse files
authored
Add files via upload
1 parent a1ad2f7 commit 559cc7d

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package testing;
2+
import java.util.*;
3+
4+
public class ComputePi {
5+
6+
public static void main(String[] args) {
7+
int i;
8+
int squre = 0;
9+
int circle = 0;
10+
double x, y;
11+
Random random = new Random();
12+
for (i = 0; i < 1000000000; i++)
13+
{
14+
int signX = random.nextInt();
15+
int signY = random.nextInt();
16+
if(signX>=0 && signY>=0){
17+
x = Math.random();
18+
y = Math.random();
19+
}else if(signX<0 && signY>=0) {
20+
x = Math.random()*-1;
21+
y = Math.random();
22+
}else if(signX >=0 && signY<0) {
23+
x = Math.random();
24+
y = Math.random()*-1;
25+
}else{
26+
x = Math.random()*-1;
27+
y = Math.random()*-1;
28+
}
29+
squre++;
30+
31+
if ( x*x + y*y <= 1 )
32+
circle++;
33+
}
34+
System.out.println("Pi = " + 4*(double)circle/(double)squre );
35+
36+
}
37+
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Approximation-of-Pi-with-Monte-Carlo-Method
2+
3+
My 9th project was in the "Fundamentals of Programming" course when I was in the 1st semester of my bachelor's at IAUSTB. This Program approximates Pi number with Monte Carlo method.
4+
5+
6+
## Monte Carlo Method
7+
| <img src="01.jpg" alt="Pascal Triangle" width="500"/> |
8+
|:--:|
9+
| *mone carlo*
10+
11+
## output
12+
| <img src="out.png" alt="Pascal Triangle" width="700"/> |
13+
|:--:|
14+
| *Output Sample*
15+
Loading

0 commit comments

Comments
 (0)