Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Malformed format string issue with a printf template

The assignment is to prompt for the radius of a circle, to calculate the area, and then print it using printf. I cannot get the error to go away after doing plenty of digging. Please, tell me what I'm doing wrong. The yellow error line appears below the printf template: "Area of the Circle is (%f)^2*3.14=%f.." -- This template was given by the professor.

    System.out.print("Enter the radius of a circle: ");
    float circleRadius = input.nextFloat();

    float circleArea = 3.14F * circleRadius * circleRadius;

    System.out.printf("Area of the Circle is (%f)^2*3.14=%f\n", circleArea);

1 Answers

You need to match each format specifier with an argument

System.out.printf("Area of the Circle is (%f)^2*3.14=%f\n", circleRadius, circleArea);
like image 58
Reimeus Avatar answered Oct 28 '25 21:10

Reimeus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!