Computer Science, asked by worldblah, 1 month ago

write a java program to display the following pattern:
*#*#*
*#*#
*#*
*#
*
please do a desk check before answering and pls execute in bluej first....please this is urgent...thanks​

Answers

Answered by sahilbadhiyasongs
0

Answer:

public Pattern

{public static void main()

{

int i, j;

for (i=5;i>=1;i--)

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

if(j%2==1)

System. out. print('*');

if(j%2==0)

System. out. print('#');

}

}

System. out. println();

}

Answered by BrainlyProgrammer
3

Given pattern:-

*#*#*

*#*#

*#*

*#

*

Similar pattern:-

12345

1234

123

12

1

Hint:-

  • If we replace even numbers with '#' and odd numbers with '*' then we will get desired pattern. So let's see how it is done..

Approach:-

public class patt{

public static void main (String ar []){

//First we'll create a pattern like 12345 1234 123 12 1

for(int I=5;I>=1;I--){

for(int j=1;j<=I;j++){

//Now we will check if j is even or not

if(j%2==0) //If yes, print "#"

System.out.print("#");

else //otherwise print "*"

System.out.print("*");

}

System.out.println(); //Next line

}

}

}

Tips:-

  • Whenever you come across this kind of question, simply write similar pattern but in numbers. It will be easy to get the logic (hint)
Attachments:
Similar questions