Homework-StaticMethod - Homework Static Methods Devin...

This preview shows page 1 - 2 out of 2 pages.

Homework: Static Methods Devin Schneider private static boolean pointIsInCircle( double xCoord , double yCoord ) { if (( xCoord - 1.0) * ( xCoord - 1.0) + ( yCoord - 1.0) * ( yCoord - 1.0) < 1) { return true ; } else { return false ; 1. } private static int numberOfPointsInCircle( int n ) { Random rnd = new Random1L(); Random rnd2 = new Random1L(); int ptsInInterval = 0, ptsInSubinterval = 0; while ( ptsInInterval < n ) { double xCoord = rnd .nextDouble() * 2.0; double yCoord = rnd2 .nextDouble() * 2.0; boolean inCircle = pointIsInCircle ( xCoord , yCoord ); ptsInInterval ++; if ( inCircle ) { ptsInSubinterval ++; } } return ptsInSubinterval ; 2. } public static void main(String[] args) { SimpleReader input = new SimpleReader1L(); SimpleWriter output = new SimpleWriter1L(); output.print( "Number of points: " ); int n = input.nextInteger(); int ptsInSubinterval = numberOfPointsInCircle(n);

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture