2.4 Develop a program that draws two sets of ever-decreasing rectangles one in outline form and one filled alternately in black and white.

Rect10.java

import java.awt.*;
import java.applet.*;
/*<applet code="Rect10.class" width=800 height=400></applet>*/

public class Rect10 extends Applet
{
int x,y,w,h;
public void paint(Graphics g)
{
x=10;
y=10;
w=300;
h=200;
for(int i=0; i<20;i++)
{
x+=5;
y+=5;
w-=10;
h-=10;
if(i%2==0)
{
g.setColor(Color.black);
g.fillRect(x,y,w,h);
}
else
{
g.setColor(Color.white);
g.fillRect(x, y,w,h);
}
}
}
}

Output

Happy Coding :)