Wednesday, July 1, 2015

// // Leave a Comment

Program To Calculate The Diameter, Circumference and Area of a Circle

The program below is the answer to Deitel's Java How to Program (9th Edition) Chapter 2 Exercise 2.28.

Question: Write an application that inputs from the user the radius of a circle as an integer and prints the circle’s diameter, circumference and area using the floating-point value 3.14159 for π. Use the techniques shown in Fig. 2.7. [Note: You may also use the predefined constant Math.PI for the value of π. Use the following formulas (r is the radius):

diameter = 2r
circumference = 2πr
area = πr2

Do not store the results of each calculation in a variable. Rather, specify each calculation as the value that will be output in a System.out.printf statement. The values produced by the circumference and area calculations are floating-point numbers. Such values can be output with the format specifier %f in a System.out.printf statement.
 * @Author: Aghatise Osazuwa
 * Website:
 * Exercise 2.28 - Diameter, Circumference and Area of a Circle
 * This Program Calculates The Diameter, Circumference and Area of a Circle

import java.util.Scanner;

public class Ex02_28 {
    public static void main (String [] args) {
        Scanner value = new Scanner (;
        int radius;
        System.out.println ("This Application \n");
        System.out.print ("Enter The Value For The Radius of The Circle: ");
        radius = value.nextInt();
        System.out.printf("\nThe diameter of the circle is %d\nThe circumference "
                + "of the circle is %f\nThe Area of the circle is %f\n",
                (2*radius), (2*Math.PI*radius), (Math.PI*radius*radius));


Click here to see other answers to Java How to Program.


Post a Comment

DISCLAIMER: Opinions expressed in comments are those of the comment writers alone and does not reflect or represent the views of the post author. We reserve the right to delete any post deemed inappropriate or offensive and/or spammy. Please do not use abusive words/hate speech.

I Appreciate your valuable Feedback. So, Please DO NOT SPAM - Spam comments will be deleted immediately.

Don't use brand name in name field and you're not allowed to use links in comments unless it's necessary. Such comments will be removed immediately. To get notified of replies or follow-up comments, click the box next to notify me.