Write a program to print a circle

Answers (1)

class GFG  
    
// 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(" "); 
     
 

// Driver code 
public static void main(String[] args) 
 
    int radius = 6; 
    printPattern(radius); 
 
 

 

Most Viewed Questions

Preparation Products

Knockout JEE Main April 2021 (One Month)

Personalized AI Tutor and Adaptive Time Table, Self Study Material, Weekend Live Classes, Mentorship from our Experts, Unlimited Mock Tests and Personalized Analysis Reports, 24x7 Doubt Chat Support,.

₹ 14000/- ₹ 4999/-
Buy Now
Knockout NEET Aug 2021 (One Month)

Personalized AI Tutor and Adaptive Time Table, Self Study Material, Weekend Live Classes, Mentorship from our Experts, Unlimited Mock Tests and Personalized Analysis Reports, 24x7 Doubt Chat Support,.

₹ 14000/- ₹ 4999/-
Buy Now
Knockout JEE Main May 2021

Personalized AI Tutor and Adaptive Time Table, Self Study Material, Weekend Live Classes, Mentorship from our Experts, Unlimited Mock Tests and Personalized Analysis Reports, 24x7 Doubt Chat Support,.

₹ 22999/- ₹ 9999/-
Buy Now
Knockout NEET Aug 2021

Personalized AI Tutor and Adaptive Time Table, Self Study Material, Weekend Live Classes, Mentorship from our Experts, Unlimited Mock Tests and Personalized Analysis Reports, 24x7 Doubt Chat Support,.

₹ 22999/- ₹ 9999/-
Buy Now
Test Series JEE Main May 2021

Unlimited Chapter Wise Tests, Unlimited Subject Wise Tests, Unlimited Full Mock Tests, Get Personalized Performance Analysis Report,.

₹ 6999/- ₹ 2999/-
Buy Now
Boost your Preparation for JEE Main with our Foundation Course
 
Exams
Articles
Questions