circle in java code example
Example 1: java create circle
ellipse(0, 0, 100, 100);
Example 2: area of circle in java
import java.util.Scanner;
public class AreaOfCircle {
public static void main(String args[]){
int radius;
double area;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the radius of the circle ::");
radius = sc.nextInt();
area = (radius*radius)*Math.PI;
System.out.println("Area of the circle is ::"+area);
}
}
Example 3: how to create a circle in java
public class scratch {
public static void main(String[] args) {
JFrame window = new JFrame();
window.setTitle("Christmas Tree");
window.setSize(700, 600);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setVisible(true);
DrawingComponent DC = new DrawingComponent();
window.add(DC);
}
}
class DrawingComponent extends JComponent{
public void paint(Graphics graph0){
Graphics2D graph = (Graphics2D) graph0;
Ellipse2D.Double circle = new Ellipse.Double(5, 5, 25, 25);
graph.fill(circle);
}
}