Write a Java program

User Generated

cflpu23

Programming

Description

I have a Java program that just needs to be tweaked to make simpler, basically just to redo the code without the loop. 

here's the code 

import java.util.*;

public class PossibleCircle 

{

  public static void main(String[] args)  

  {

    Scanner input = new Scanner(System.in);

   

    int runningTotal = 0;

    int currentInput; 

    int[] radius_inch = new int[5];

int total=0;

double area;

double circumference;

double radius_cm;

double average;

    final double IN_TO_CM = 2.54;

System.out.println("Enter radius for each circle in inches");

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

{

System.out.print("Enter radius of circle "+ (i+1) + ":" );

radius_inch[i] = input.nextInt();

total = total + radius_inch[i];

}

        System.out.print("Radius (in.)  ");

        System.out.print("Radius (cm.)  ");

        System.out.print("Area (sq. cm.)  ");

        System.out.println("Cirumference (sq. cm.)");

System.out.println("__________________________________________________________________________________________________");

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

           

{

radius_cm = IN_TO_CM * radius_inch[i];

area =  Math.PI * radius_cm * radius_cm;

circumference = 2 * Math.PI * radius_cm;

System.out.printf("%10d\t\t%10.1f\t\t%10.1f\t\t%10.1f\n",radius_inch[i],radius_cm,(double)Math.round(area*10)/10, (double)Math.round(circumference*10)/10);

}

average = total/5;

double d = (double)Math.round(average*10)/10;

    System.out.println("The average of all the radii is:" + d +" inches.");

  }

}


User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

This question has not been answered.

Create a free account to get help with this and any other question!

Related Tags