import java.awt.Color;
import java.awt.Graphics;
import java.util.Random;
public class RandomColorSquare {
private static final int SIDE_LENGTH = 50;
public static void main(String[] args) {
Random random = new Random();
Color randomColor = new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256));
Graphics g = new Graphics();
g.setColor(randomColor);
g.fillRect(g.getWidth()/2 - SIDE_LENGTH/2, g.getHeight()/2 - SIDE_LENGTH/2, SIDE_LENGTH, SIDE_LENGTH);
}
}
Write a program that draws a random color square centered on the graphics canvas. The sides of the square should be SIDE_LENGTH.
(Hint: Use the Randomizer to get a random color for the square.)
2 answers
this is so epic i can't believe it