-
-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathcircle.java
More file actions
39 lines (30 loc) · 885 Bytes
/
circle.java
File metadata and controls
39 lines (30 loc) · 885 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import java.io.*;
class circle {
// function to print circle pattern
static void printPattern(int radius) {
// dist represents distance to the center
double dist;
// for horizontal movement
for (int i = 0; i <= 2 * radius; i++) {
// for vertical movement
for (int j = 0; j <= 2 * radius; j++) {
dist = Math.sqrt((i - radius) * (i - radius) +
(j - radius) * (j - radius));
// dist should be in the range (radius - 0.5)
// and (radius + 0.5) to print stars(*)
if (dist > radius - 0.5 && dist < radius + 0.5)
System.out.print("*");
else
System.out.print(" ");
}
System.out.print("\n");
}
}
// Driver code
public static void main(String[] args)
{
DataInputStream in=new DataInputStream(System.in);
int radius = 6;
printPattern(radius);
}
}