Kanjut SHELL
Server IP : 172.16.15.8  /  Your IP : 3.12.73.149
Web Server : Apache
System : Linux zeus.vwu.edu 4.18.0-553.27.1.el8_10.x86_64 #1 SMP Wed Nov 6 14:29:02 UTC 2024 x86_64
User : apache ( 48)
PHP Version : 7.2.24
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0705) :  /home/zwang/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/zwang/TextCircle.java
import java.math.*;

public class TextCircle
{
	private static final int DEFAULT_LINES = 12;


	public static void main(String[] args)
	{
		int lines;

		// get the lines
		try
		{
			lines = Integer.parseInt(args[0]);
		}
		catch (Exception e)	// in case there is a problem
		{
			System.out.println("Argument was not specified, or was not an integer. Using default.");
			lines = DEFAULT_LINES; // some defaule value
		}

		// output that you have the value
		System.out.println("Lines = "+lines+"\n--------------------\nSTART DRAWING CIRCLE\n--------------------\n");

		// calculate the circle and output
		for(int i=0;i<lines;i++)
		{
			for(int j=0; j<lines; j++)
			{
				if(intersectsCircle(i,j,lines))
					System.out.print('*');
				else
					System.out.print(' ');

				System.out.print(' ');
			}

			System.out.print('\n'); // newline
		}
		System.out.println("\n-----------------------\nFINISHED DRAWING CIRCLE\n-----------------------");
	}

	/*
		This method checks if this space lies on the circle
	 */
	private static boolean intersectsCircle(int i, int j, int lines)
	{
		// find the center of the circle
		// for this cirlce, centerX = centerY = raduis
		// subtract one from lines because the first line is line #0
		double radius = (double)(lines-1)/2;

		double distance = Math.sqrt((radius-i)*(radius-i) + (radius-j)*(radius-j));
		double difference = distance - radius;

		if(difference <= .25 && difference >= -.25)
			return true;

		// else
		return false;
	}
}

Stv3n404 - 2023