Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Using Math.Random

  1. #1
    Junior Member
    Join Date
    Apr 2024
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Using Math.Random

    Using Math.random need to find the radius of 10 circles and need to find the area of each circle Need help to write a program solution

  2. #2
    Member Helium c2's Avatar
    Join Date
    Nov 2023
    Location
    Kekaha, Kaua'i
    Posts
    117
    Thanks
    1
    Thanked 3 Times in 3 Posts

    Default Re: Using Math.Random

    radius = C/2 * pi. Area? I didn't know there was an area. 10 * radius = close to the total area. Just not quite. A little off but close. This is the closest method I can think of in math.

  3. #3
    Member
    Join Date
    Jan 2024
    Posts
    75
    Thanks
    0
    Thanked 4 Times in 4 Posts

    Default Re: Using Math.Random

    Sure, here's a simple Java program that uses `Math.random` to generate the radius of 10 circles and then calculates the area of each circle:

    ```java
    public class CircleAreaCalculator {
    public static void main(String[] args) {
    // Define the number of circles
    int numberOfCircles = 10;

    // Iterate through each circle
    for (int i = 1; i <= numberOfCircles; i++) {
    // Generate a random radius between 1 and 10
    double radius = Math.random() * 10 + 1;

    // Calculate the area of the circle
    double area = Math.PI * radius * radius;

    // Print the radius and area of the circle
    System.out.println("Circle " + i + ": Radius = " + radius + ", Area = " + area);
    }
    }
    }
    ```

    This program generates a random radius for each circle using `Math.random() * 10 + 1`, which generates a random number between 1 and 10 inclusive. It then calculates the area of each circle using the formula `area = π * radius^2`, where π is approximately 3.14159. Finally, it prints out the radius and area of each circle.

    Lastly, if you require further help with Java assignment or any programming tasks, feel free to explore additional resources available online like ProgrammingHomeworkHelp.com. Various platforms offer guidance and support to enhance your understanding of programming concepts. Additionally, seeking help from academic resources can provide valuable insights and clarification on complex topics. Remember, learning is a continuous process, and seeking assistance when needed is a sign of dedication to mastering the subject.

Similar Threads

  1. [SOLVED] Counting and Math.random
    By Elyril in forum What's Wrong With My Code?
    Replies: 30
    Last Post: March 9th, 2014, 08:12 PM
  2. Java Math.random() and loop
    By maple1100 in forum What's Wrong With My Code?
    Replies: 23
    Last Post: December 28th, 2012, 12:23 PM
  3. Math.random() with no duplictaes
    By jaydac12 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: December 6th, 2012, 07:42 AM
  4. Problems with Math.Random() in a for loop
    By csharp100 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: September 27th, 2012, 06:18 PM
  5. Math.Random()
    By xionyus in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 26th, 2011, 10:22 PM