Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 896401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:43:28+00:00 2026-05-15T14:43:28+00:00

Simple program to just find the circumference, diameter, and area of a circle. Whenever

  • 0

Simple program to just find the circumference, diameter, and area of a circle. Whenever I run the program it’s fine, just at the end there’s always a 1 or -1 after the value for Area. For example, when using a radius of 10 I get:

Results
The circumference of the circle is: 62.832 Centimeters
The diameter of the circle is: 20.0 Centimeters
The area of the circle is: 314.159 Centimeters1

Code is as follows below:

import javax.swing.JOptionPane;
import java.text.DecimalFormat;

public class Circle {

    public static void main(String[] args)
    {
    //Declarations
    double radius;
    String getRadius;

    //Formatting
    DecimalFormat formatter = new
    DecimalFormat(".000");

    //Calculations
    getRadius = JOptionPane.showInputDialog("Enter Circle Radius In Centimeters:");
    radius = Double.parseDouble(getRadius);

    //Output
    JOptionPane.showMessageDialog(null, "Results" + 
            "\n The circumference of the circle is: " + formatter.format(2*Math.PI*radius) + " Centimeters" +
            "\n The diameter of the circle is: " + 2*radius + " Centimeters" +
            "\n The area of the circle is: " + formatter.format(Math.PI*Math.pow(radius,2)) + " Centimeters" +
            JOptionPane.INFORMATION_MESSAGE);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T14:43:28+00:00Added an answer on May 15, 2026 at 2:43 pm

    You’re appending JOptionPane.INFORMATION_MESSAGE (which happens to equal 1) to your string. It should be something like:

    JOptionPane.showMessageDialog(null, 
            "Results" + 
            "\n The circumference of the circle is: " + formatter.format(2*Math.PI*radius) + " Centimeters" +
            "\n The diameter of the circle is: " + 2*radius + " Centimeters" +
            "\n The area of the circle is: " + formatter.format(Math.PI*Math.pow(radius,2)) + " Centimeters", 
            "Results", 
            JOptionPane.INFORMATION_MESSAGE);
    

    The four parameters are parent, message, title, messageType. Before, you were accidentally using the two-parameter version (parent, message) and appending the messageType to your message.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was making this very simple lex program (just an introductory program). But on
Is it just to test compile a simple program, with that header file #included
I have just started on AWT and made a simple program in it, it
I've just started programming in Qt framework. Following is a very simple program: #include
I'm just learning Ruby and making a simple Hello World program, put for some
Basically, I just need to write a simple java program to detect the version
Writing a simple program that will find exact duplicate files on my computer, but
i am trying to run a very simple java program. i want to write
I just tried to write a simple C program on OSX Lion #include <stdio.h>
I am just playing around with code blocks and writing a very simple program,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.