Question :

Write a java program to find circumference and area of a circle. Your program should be fulfill following requirements.
 Radius of the circle should be read in the main method of the program
 Circumference and Area should be calculated at the circumference() and area() methods.
 Circumference and Area should be displayed at the main method.

My answer :

import java.util.Scanner;

class circles{
public static void main(String [] args){}

Scanner in = new Scanner(System.in);
int radius = in.nextInt();

circumference(radius);
area(radius);

double c1 = circumference(c);
System.out.print("Circumference of the circle is = "+c1);

double a1 = area(a);
System.out.print("Area of the circle is = "+a1);

static double circumference(int r){

double c = 2*3.14*r;
return c;
}

static double area(int r){

double a = 3.14*r*r;
return a;
}

}

Could anyone please point out the mistakes of my code?

Thanks!

1 answer

looks ok
is there a reason you restrict r to integer values? Maybe because you only know about integer input?

Did you actually run it? check your results with a calculator?
As my first employer (a former NASA engineer) liked to say,
One measurement is worth a thousand expert opinions.