IN FORM OF JAVA OPERATION:
CREATE A PROGRAM THAT WOULD:
Create a program solution of the given problem using Java Programming.
Use basic system input/output of Java Programming
Apply java arithmetic
Instruction:
Read and analyze each problem. Provide a JAVA program to satisfy the required
machine functionality.
Import all java utilities using the syntax: Import java.util.*;
Machine Problem:
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.
INPUT: A positive real number (between 0.001 and 1000, inclusivein a single line denoting the radius, r.
OUTPUT: For each test case, output the area of the minimum squarewhere 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.
TEST CASE #1
INPUT: 0.1
OUTPUT: 0.34383
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Scanner;
public class SquareSize {
public static void main(String[] args) {
// TODO Auto-generated method stub
double a;
double b;
System.out.println("Please enter value of radius of the circle:");
Scanner sc=new Scanner(System.in);
a=sc.nextFloat();
b=(2*Math.sqrt(2)+2*Math.sqrt(3)+2)*a/Math.sqrt(2);
b=b*b;
NumberFormat formatter = new DecimalFormat("##.00000");
System.out.println("The required area of the rectangle is:"+formatter.format(b));
}
}
Comments
Leave a comment