Answer to Question #161646 in Java | JSP | JSF for aj

Question #161646

create a program in java:

You have 8 circles of equal size and you want to pack them inside a square. You want to minimize the size of the square. The following figure illustrates the minimum way of packing 8 circles inside a square:

Given the radius, r, find the area of the minimum square into which 8 circles of that radius can be packed.


The Input:


A positive real number (between 0.001 and 1000, inclusive) in a single line denoting the radius, r.


The Output:


For each test case, output the area of the minimum square where 8 circles of radius r can be packed. Print 5 digits after the decimal.


Your output is considered correct if it is within ±0.00001 of the correct output.



1
Expert's answer
2021-02-06T00:58:53-0500
public class Main {
    public static void main(String[] args) {
        double r = 0.1;
        double height = r * 2 * Math.sqrt(3) / 2;
        double square = r * r;
        double hypo = Math.sqrt(square + square);
        double d = 2 *(height + r + hypo);
        double a = d / Math.sqrt(2);
        System.out.printf("%.5f",a*a);
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog