Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I keep getting an error every time i try to calculate the diameter

My code works fine until I try to calculate the Diameter. I ran the program while only calculating the area and circumference and it works. But as soon as I try to calculate the diameter I keep getting an error.

package calccircumference;


import java.util.Scanner;

public class CalcCircumference {

    
    public static void main(String[] args) {
        Scanner input = new Scanner( System.in );
        int radius;
        
        System.out.print("Enter radius of circle: ");
        radius = input.nextInt();
        
        
        System.out.printf("Diameter is %f\n",( 2*radius ));
        
        System.out.printf( "Area is %f\n", ( Math.PI * radius * radius ) );
        
        System.out.printf("Circumference is %f\n",(2 * Math.PI * radius));
        
        
    }
    
}

[enter image description here][1]


  [1]: https://i.stack.imgur.com/2X0Dp.png

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

An integer multiplied by an Integer will give you an Integer so change to

System.out.printf("Diameter is %f\n",( 2.0 *radius ));

Or use

System.out.printf("Diameter is %d\n",( 2 *radius ));
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading