Computer Science, asked by pavnishrigupta59, 10 months ago

WAP in Java to print the following
pattern.
a
a a
a a a
a a a a
a a a a a
​please answer my question

Answers

Answered by mantasha89
0

Answer:

I don't know your question

Answered by MissSolitary
9

—› Your Program:

{ \gray{ \sf{//java \: program \: to \: print \: the \: following \: pattern}}}

 \sf \: import \: java.util. {}^{*} ;

 \sf \: public \: class \: pattern

{

 \:  \:  \: \sf \: public \: static \: void \: main(String  \: args[ \: ] \: )

{

 \:  \:  \:  \sf \: Scanner \: in \:  =  \: new \:  Scanner(System.in);

 \:  \:  \:  \sf \: int \: n,i, j;

 \:  \:   \:  \sf \: System.out.println("Enter  \: the \: no. \: of \: rows \: to \: print \: the \: pattern");

 \:  \:  \:  \sf \: n = in.nextInt();

 \:  \:   \:  \sf \: for(int \: i = 1;i <  = n;i++ )

{

 \:  \:  \:  \sf \: for(j = 1;j < = i;j++ )

{

 \:  \:   \:  \sf \:System.out.print(❝ a ❞);

}

 \:  \:   \:  \sf \: System.out.println(' \:  \:  \: ');

}

}

}

--------------------------

—› Output:

Enter the no. of rows to print the pattern

5

a

a a

a a a

a a a a

a a a a a

--------------------------

—› Variable Description:

  • n = to take the input from the user to enter the no. of rows as I have used scanner class.
  • i , j = to run the loop

---------------------------

—› Note:

  • println() - It is used to print after each next line.
  • print() - It is used to print in the same line.

---------------------------

Similar questions