Skip to content
Advertisement

Using a final double variable in java [closed]

I’m making a small program that asks the user for the radius of a circle and then outputs the radius, diameter, area, and circumference of the circle in java. I was asked to use a final double to declare the number pi, and I need to use that later in the code to calculate values. I’m having issues with declaring/using the variable and I’m not sure what I’m doing wrong.

I get this error when running the code:

enter image description here

Main.java :

JavaScript

Circle.java :

JavaScript

Advertisement

Answer

It’s a typo,final double pi = 3.14159; need to be declared inside Circle and final double Pi = 3.14159; is never used in Main

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement