Q:

(Random point) Write a program that displays a random coordinate in a rectangle. The rectangle is centered at (0, 0) with width 100 and height 200

0

(Random point) Write a program that displays a random coordinate in a rectangle. The rectangle is centered at (0, 0) with width 100 and height 200.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

/*
(Random point) Write a program that displays a random coordinate in a rectangle.
The rectangle is centered at (0, 0) with width 100 and height 200.
*/
public class Exercise_03_16 {
	public static void main(String[] args) {
		// Generate random width and height
		int width = (int)((Math.random() * (50 + 50)) -50);
		int height = (int)((Math.random() * (100 + 100)) -100);

		// Display coordinate
		System.out.println("Random coordinate in rectangle centered at (0,0)");
		System.out.println(
			"with width 100 and height 200: (" + width + ", " + height + ")");
	}
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now