+ 1
I just wanted to ask if my codes are good or there is a shorter or more effective way to make It?
https://code.sololearn.com/c8WM3tsxYTf9/?ref=app https://code.sololearn.com/c23sFfTvrpz7/?ref=app
2 ответов
+ 2
tips for surface
for pi use
Math.PI
float point numbers input
double r = in.nextDouble();
output with round to 2 dec
System.out.printf("Radius = %.2f , Height = %.2f\n", r, h);
string + string write as one stringstring
// System.out.println(" = " + "2 × pi × r × h" + " = " + " 2 " + " × " + "3.14" + " × " + r + " × " + h);
System.out.println(" = 2 × pi × r × h = 2 × 3.14 × " +r +" × " +h);
add empty lines between results
System.out.println();
it is better to keep part for calculations separate from the output
next you can add class Cylinder with two static methods
curvedArea(double radius, double height)
totalArea(double radius, double height)
and call it
System.out.println(" = " +Cylinder.totalArea(r, h) );
0
Thanks Man!