Practice Exercises Java - Learn to program performing exercises with Java

Practice Exercises Java

Learn to program performing exercises with Java

12 Lessons Java with the Solutions - 228 Exercises Java with the solutions
For Beginners, Intermediates and Advanceds

App Practice Exercises Java

The human knowledge belongs to the world
¬°The infomation should be free!

Exercises Java with Examples-
Practice Exercises Java 4,5 5 302940
Google Ads

Two dimensional array 2: circunference on screen - Practice Exercises Java

Lesson 4:

Structures and Strings

Exercise 4.22:

Two dimensional array 2: circunference on screen


Create a Java program that declares creates a 70x20 two-dimensional array of characters, "draws" a circumference or radius 8 inside it, and displays it on screen.

Hint: the points in the circumference can be obtained using:
x = xCenter + r * cos angle
y = yCenter + r * sin angle

"sin" and "cos" expect the angle to be measured in radians, instead of degrees. To convert from one unit to the other, you must remember that 360 degrees = 2 PI radians (or 180 degrees = PI radians): float radians = (angle * Math.PI / 180.0);

You might draw 72 points (as there are 360 degrees in a circumference, they would be spaced 5 degreees from each other)

Hint: in Java, cosine is Math.Cos, sine is Math.Sin and PI is Math.PI

Source Code:

public class Main
	public static void main(String[] args)
		double r, x, y;

		for (int i = 0; i < 360; i += 5)
			rad = i * Math.PI / 180.0;
			x = 35 + 8 * Math.cos(rad);
			y = 10 + 8 * Math.sin(rad);

			Console.SetCursorPosition((int)x, (int)y);

		Console.SetCursorPosition(1, 20);
Exercisey 4.22

Share Now:

Google Ads

Privacy Policy:

Google uses associated advertising companies to serve ads when it visits our website. These companies may use the information they obtain from your visits to this and other websites (not including your name, address, email address, or phone number) to provide you with announcements about products and services that interest you. If you would like to learn more about this practice and know your options to prevent these companies from using this information. Click in... Privacy and Terms of Google.


This site uses Google cookies to provide its services, to personalize advertisements and to analyze traffic. Google receives information about your use of this website. More information in... Privacy and Terms of Google.