Question: Someone please help. I've had two experts try this. The first one got it wrong and the second one gave me the picture that I

Someone please help. I've had two experts try this. The first one got it wrong and the second one gave me the picture that I presented as the answer along with wrong code. This is the code I currently have but it is wrong and I cannot figure it out.
public class SierpinskiSquare {
public static void main(String[] args){
int n = Integer.parseInt(args[0]);
StdDraw.setScale(0,1);
sierpinski(n,0.5,0.5,0.5);
}
public static void sierpinski(int n, double x, double y, double size){
double halfSize = size /2;
if (n ==0){
StdDraw.setPenColor(0,0,0);
double[] px ={ x + size, x, x - size, x };
double[] py ={ y, y + size, y, y - size };
StdDraw.filledPolygon(px, py);
return;
}
if (n %2==0){
StdDraw.setPenColor(0,0,0);
double[] px ={ x + size, x, x - size, x };
double[] py ={ y, y + size, y, y - size };
StdDraw.filledPolygon(px, py);
}else{
StdDraw.setPenColor(125,0,0);
StdDraw.filledSquare(x, y, halfSize);
}
sierpinski(n -1, x - halfSize, y - halfSize, halfSize);
}
}
Someone please help. I've had two experts try

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting Questions!