Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // class draw pyramid sync - pass char
- class PyramidDemo
- {
- public static void main(String args[])
- {
- Draw d = new Draw();
- DrawStar ds = new DrawStar(d,'*');
- DrawDollar dd = new DrawDollar(d,'$');
- ds.start();
- dd.start();
- }
- }
- class Draw
- {
- synchronized void drawPyramid(char ch)
- {
- for(int i=0;i<5;i++)
- {
- for(int j=5-i;j>1;j--)
- {
- System.out.print(" ");
- }
- for(int j=0;j<=i;j++)
- {
- System.out.print(ch + " ");
- }
- System.out.println(" ");
- }
- }
- }
- class DrawStar extends Thread
- {
- Draw d;
- char ch;
- DrawStar(Draw d,char ch)
- {
- this.d = d;
- this.ch = ch;
- }
- public void run()
- {
- d.drawPyramid(ch);
- }
- }
- class DrawDollar extends Thread
- {
- Draw d;
- char ch;
- DrawDollar(Draw d,char ch)
- {
- this.d = d;
- this.ch = ch;
- }
- public void run()
- {
- d.drawPyramid(ch);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment