# Question in numbering

• September 18th, 2010, 09:35 AM
cppcppcpp
Question in numbering
Code java:

```public class Area { public static void main(String[] args) { double radius; double area; radius = 10; area = radius * radius * 3.1415 ; System.out.println("The area of circle is " + area + "."); } }```
I am a newbie here. LOL
I would like to ask why the result comes:

"The area of circle is 314.15000000000003." ???
• September 18th, 2010, 11:07 AM
copeg
Re: Question in numbering
What output would you expect?
• September 18th, 2010, 11:49 AM
aussiemcgr
Re: Question in numbering
This is a normal thing. Your computer can only be so accurate. It is not a program problem, but rather that you computer has calculated it as best as possible. I don't really know how to explain it.
• September 18th, 2010, 12:55 PM
Darryl.Burke
Re: Question in numbering
• September 20th, 2010, 02:51 PM
cppcppcpp
Re: Question in numbering
Quote:

Originally Posted by copeg
What output would you expect?

I just expect it was

"The area of circle is 314.15." before
• September 21st, 2010, 12:17 AM
Darryl.Burke
Re: Question in numbering
Now go through the page I linked and correct your expectations.

db
• September 22nd, 2010, 08:52 AM
sanz
Re: Question in numbering
if you want to your answer to be displayed 314.15, you should put, "%2f, area" if im not mistaken its look like in the C programming it will just put 2 decimal place, i hope it can helps you.
• September 22nd, 2010, 08:55 AM
sanz
Re: Question in numbering
instead of this System.out.println("The area of circle is " + area + "."); use this System.out.printf("The area of cirlcis %3f" , area); so that the modulo will be read in the java compiler, with no problem
• September 22nd, 2010, 09:59 PM
asdfg
Re: Question in numbering
@sanz:
you're right..it's like C progmramming...

@cppcppcppcpp

change the System.out.println("The area of circle is " + area + ".");
to:
System.out.printf("The area of cirle is %.2f" , area);
• September 24th, 2010, 03:49 PM
ByteITGTA
Re: Question in numbering
Should be getting 314.15 for the area... I got it..
Now get more fun with it and require input from user.

import java.util.*;

public class Area {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
double area;