Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathcircle.java
More file actions
Latest commit
39 lines (30 loc) · 885 Bytes
/
Copy pathcircle.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
importjava.io.*;
classcircle {
// function to print circle pattern
staticvoidprintPattern(intradius) {
// dist represents distance to the center
doubledist;
// for horizontal movement
for (inti = 0; i <= 2 * radius; i++) {
// for vertical movement
for (intj = 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
publicstaticvoidmain(String[] args)
{
DataInputStreamin=newDataInputStream(System.in);
intradius = 6;
printPattern(radius);
}
}