Question

Determining t Experimentally Recall that π is the ratio of a circles circumference to its diameter and that we can calculate the area of a circle with the formula A-r Below is a circle enscribed within the unit square What is the ratio of the areas of the enscribed circle to that of the unit square? If we pick a random point within the unit square what is the probability that the point will also lie within the circle? If we repeat this experiment an arbitrarily large number of times the ratio of the number of points which lie within the circle to the number of points within the unit square (all of them) will approach π4 Using the language structures we have discussed write a program that will do the above experiment an arbitary (determined at run-time) number of times and report back the approximate value of u.

CODE IN JAVA PLEASE MAKE SURE IT 'LL COMPILE AND RUN

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hey,

Below is the code to your question

import java.util.Scanner;

import java.util.Random;

public class PI

{

public static int checkPoint(double x,double y)

{

if(x*x+y*y<=1)

return 1;

return 0;

}

public static void main(String[] args)

{

int counts=0;

Random rand = new Random();

Scanner sc = new Scanner(System.in);

System.out.println("Enter number of times: ");

int n=sc.nextInt();

for(int i=0;i<n;i++)

{

double x = 2.0*rand.nextDouble()-1.0;

double y = 2.0*rand.nextDouble()-1.0;

if(checkPoint(x,y)==1)

{

counts++;

}

}

double Pi=4.0*(double)counts/(double)n;

System.out.printf("The vlue of PI is estimated as %.4f\n",Pi);

}

}

1000 Copy RunRun+URL (Generates URL as well) Time(sec): 0.12 Memory (MB) : 56.2617 Output: Copy Enter number of times: The vl

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
CODE IN JAVA PLEASE MAKE SURE IT 'LL COMPILE AND RUN Determining t Experimentally Recall that...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please Implement this code using Java Eclipse. CIS 1068 Assignment 8 Warm Up with Objects Due:...

    Please Implement this code using Java Eclipse. CIS 1068 Assignment 8 Warm Up with Objects Due: Wednesday, March 25 70 points (+ up to 15 extra credit) The purpose of this assignment is to give you practice implementing your own classes. It also provides extra practice with arrays. Task Implement a class Task, which is used to represent a job that should be done. It should contain the following private fields: .name text description of what job should be done...

  • CS0007 Good day, I am in an entry-level Java class and need assistance completing an assignment....

    CS0007 Good day, I am in an entry-level Java class and need assistance completing an assignment. Below is the assignment criteria and the source code from the previous assignment to build from.  Any help would be appreciated, thank you in advance. Source Code from the previous assignment to build from shown below: Here we go! Let's start with me giving you some startup code: import java.io.*; import java.util.*; public class Project1 { // Random number generator. We will be using this...

  • Consider a cylindrical capacitor like that shown in Fig. 24.6. Let d = rb − ra...

    Consider a cylindrical capacitor like that shown in Fig. 24.6. Let d = rb − ra be the spacing between the inner and outer conductors. (a) Let the radii of the two conductors be only slightly different, so that d << ra. Show that the result derived in Example 24.4 (Section 24.1) for the capacitance of a cylindrical capacitor then reduces to Eq. (24.2), the equation for the capacitance of a parallel-plate capacitor, with A being the surface area of...

  • I need help with my very last assignment of this term PLEASE!!, and here are the instructions: After reading Chapter T...

    I need help with my very last assignment of this term PLEASE!!, and here are the instructions: After reading Chapter Two, “Keys to Successful IT Governance,” from Roger Kroft and Guy Scalzi’s book entitled, IT Governance in Hospitals and Health Systems, please refer to the following assignment instructions below. This chapter consists of interviews with executives identifying mistakes that are made when governing healthcare information technology (IT). The chapter is broken down into subheadings listing areas of importance to understand...

  • Please read the article and answer about questions. You and the Law Business and law are...

    Please read the article and answer about questions. You and the Law Business and law are inseparable. For B-Money, the two predictably merged when he was negotiat- ing a deal for his tracks. At other times, the merger is unpredictable, like when your business faces an unexpected auto accident, product recall, or government regulation change. In either type of situation, when business owners know the law, they can better protect themselves and sometimes even avoid the problems completely. This chapter...

  • Read “Instituionalizing our Demise: America vs Multiculturalism” by Roger Kimball on pg 268 and “Reinventing America”...

    Read “Instituionalizing our Demise: America vs Multiculturalism” by Roger Kimball on pg 268 and “Reinventing America” Call for a new national indentity” by Elizabeth Martinez on pg 275. Create a double entry notebook for each reading selection It should be atleast five observation and responses. wric 268 PART 2 essay pro. exactly how and why their authors disagree. Instead of with parties in conflict as mediators do, you will nt of view designed to appeal to both sides, mediatn posing...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT