Computer Science, asked by Anonymous, 1 year ago

WAP in JAVA to print a pattern of sandglass



Plz don't COPY from google

Answers

Answered by Anonymous
1

CODE :

class pattern_sandglass

{

public static void main(String args [ ])

{

for(int i=1;i<=5;i++)

{

for(int j=1;j<=i;j++)

{

System.out.print(" ");

}

System.out.print("$ ");

for(int k=5;k>=i;k--)

{

System.out.print("$ ");

}

System.out.print("$ ");

System.out.println();

}

for(int i=1;i<=5;i++)

{

for(int j=5;j>=i;j--)

{

System.out.print(" ");

}

System.out.print("$ ");

for(int k=1;k<=i;k++)

{

System.out.print("$ ");

}

System.out.print("$ ");

System.out.println();

}

}

}


OUTPUT :

In the attachment !


NOTE :

⇒ If you want to print the pattern for n terms then instead of running the loop 5 times , run it for n times and use .util package

⇒ Also if you want inputs then introduce Scanner class and other statements which are necessary.

⇒ If you use any other method or loop like while loop then follow the logic but change the syntax .

Best of luck !!

Hope it helps !

_____________________________________________________________________

Attachments:

Anonymous: Nice !!
Anonymous: thanks :-)
Anonymous: :-)
Similar questions