I have an assignment that lets people enter a shape and side lengths/the radius and gives an area and circumference/perimeter. The issue I am having however is out of my depth.
area = (Math.PI) * (radius) * (radius);
circumference = 2 * Math.PI * radius;
System.out.printf("The circumference is: %f\n", circumference);
System.out.printf("The area is: %f\n", area);
String areaString = String.valueOf(area);
String perimeterString = String.valueOf(circumference);
System.out.println("Total number of digits in the circumference is: " + areaString.length());
System.out.println("Total number of digits in the area is: " + perimeterString.length());
This is the code. The radius was entered before. If it makes any difference the area is a double and the value inputed by the user is an integer. So the output of the code is:
The circumference is: 69.115038
The area is: 380.132711
Total number of digits in the circumference is: 17
Total number of digits in the area is: 17
So what I believe is happening is the double's length is actually more than is being printed out (obviously pi is irrational). However, when I change the first print statement to:
System.out.println("Total number of digits in the circumference is: " + (areaString.length()-1));
eclipse still prints out 17. If there is anyone out there more experienced I would appreciate some advise.