Computer Science, asked by tiger002, 11 months ago

please show me its a loop programming concept ​

Attachments:

Answers

Answered by sswaraj04
2

Answer:

public class MainClass

{

public static void main(String[] args)

{

 

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

 {

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

  {

   System.out.print(j);

  }

 

  System.out.println();

 }

 System.out.println("new pattern");

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

 {

  for (int j = 6-i; j>= 1; j--)

  {

   System.out.print(j);

  }

 

  System.out.println();

 }

 System.out.println("new pattern");

 

 for (int i = 7; i>= 1; i=i-2)

 {

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

  {

   System.out.print(j);

  }

 

  System.out.println();

 }

 System.out.println("new pattern");

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

 {

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

  {

   System.out.print("@");

  }

 

  System.out.println();

 }

   

}

}

Explanation:

I have made all patterns in single program

you can seperate it out

in making any pattern

outer loop is always used for no. of rows and inner loop is adjusted so that to make the required pattern...


rakeshchennupati143: we can write every patter into one line of System.out.print() method
sswaraj04: i didn't expected this from you!!!!
rakeshchennupati143: why am i being childish? :/
sswaraj04: yeah of course....lol
rakeshchennupati143: i dont
rakeshchennupati143: i don't know since when i started seeing these patterns every time i think why the they use nested loops LOL XD
sswaraj04: me too when i read it first in 9th and even in the textbook(sumita arora:-which i read ) there was pattern made just by using system.out.println and i thought that's it... now all question are solved
sswaraj04: but once when i showed to teacher he said don't be oversmart ....LOL :-)
sswaraj04: and that's mine answer to you too .......haha
rakeshchennupati143: haha LOL i have been carrying that questions since from my 12 class, when i ask everyone i know about this they laughed and said LOL
Similar questions