Computer Science, asked by aryanchakra14, 1 month ago

write a program to print
@@@@1
@@@2@
@@3@@
@4@@@
5@@@@
Plz give me the answer fast

Answers

Answered by anindyaadhikari13
4

\textsf{\large{\underline{Solution}:}}

As no language is mentioned, I am writing in Java.

Here comes the co‎de.

public class Brainly{

   public static void main(String s[]){

       int i,j,n=5;

       for(i=1;i<=n;i++){

           for(j=1;j<=n;j++){

               if(i+j==n+1)

                   System.out.print(i+" ");

               else

                   System.out.print("@ ");

           }

           System.out.println();

       }

   }

}

\textsf{\large{\underline{Explanation}:}}

  • Line 1: Class declaration.
  • Line 2: Start of main() method.
  • Line 3: Declared 3 variables, to be used while printing the pattern.
  • Line 4: Start of outer loop.
  • Line 5: Start of inner loop.
  • Line 6: A condition which checks whether numbers should be printed or not.
  • Line 7: If condition in line 6 is true, number is printed.
  • Line 8-9: If condition is false, '@' symbol is printed.
  • Line 10: End of inner loop.
  • Line 11: A new line is inserted so as to move to the next row.
  • Line 12: End of outer loop.
  • Line 13: End of main() method.
  • Line 14: End of class.

See attachment for output.

Attachments:

anindyaadhikari13: Thanks for the brainliest :)
Answered by kamalrajatjoshi94
2

Answer:

Program:-

public class Main

{

public static void main(String args[])

{

int p=5,c=1;

System.out.println("The pattern:");

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

{

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

{

if(j==p)

System.out.print(c+" ");

else

System.out.print("@"+" ");

}

System.out.println();

p--;

c++;

}

}

}

Logic:-

  • Simple first make a program that prints five rows and five columns
  • Then make a condition that if iteration number is 5 then it prints 1 followed by 4th iteration 2
  • If condition is false it prints "@".
Attachments:
Similar questions