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

  • Home
  • SEARCH
  • 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 8931111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:02:20+00:00 2026-06-15T09:02:20+00:00

help, I want the output of the program to be rounded to 2 decimal

  • 0

help, I want the output of the program to be rounded to 2 decimal places…………………………………………………………………………………………………………………………………………………………

here is my code :

package javaapplication2;
import javax.swing.JOptionPane;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class NewClass {
    public static void main(String[ ] args){

int age = 0;             
age = Integer.parseInt(
JOptionPane.showInputDialog(
null, "Enter radius of a circle: "));  

        int radius = 0;
        System.out.println("Enter radius of a circle : ");
        try
        {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            radius = Integer.parseInt(br.readLine());
        }
        catch(NumberFormatException ne)
        {
            System.out.println("Invalid radius value" );
            System.exit(0);
        }
        catch(IOException ioe)
        {
            System.out.println("IO Error :" + ioe);
            System.exit(0);
        }
        radius = 5;
        double circumference = 2 * Math.PI * radius;
        double area = Math.PI * radius * radius;

        System.out.println("Area of a circle is " + area);
        System.out.println("Perimeter of a circle is " + circumference);

        }
}  
  • 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-06-15T09:02:21+00:00Added an answer on June 15, 2026 at 9:02 am

    As you only want to display rounded values, rather than pass it on for use in further calculations, you could use DecimalFormat:

    DecimalFormat format = new DecimalFormat("0.##");
    System.out.println("Area of a circle is " + format.format(area));
    System.out.println("Perimeter of a circle is " + format.format(circumference));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I tried the below program . INPUT-: i want help Desired OUTPUT-:Words=3 Characters=9 But
I want a program that would help me create virtual devices on a virtual
I want to invoke a program on the webpage and get it output on
Here, i have a program, which takes arguments (how surprising...). I want him to
OK so I redefined my last program... here it is: import java.io.BufferedReader; import java.io.InputStreamReader;
guys can you help me with my code.. i want to edit a specific
i want to code a manager program in java which will execute a c
I have this program which does not work as expected. Help me. I want
I want to enable my program to output Greek letters. I've got ICU installed
I want help on this script I am making... I want my website to

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.