Computer Science, asked by parasgoyal0201, 1 year ago

Print the following pattern in JAVA
*
*#
*#*
*#*#

Answers

Answered by Anonymous
28

//A program in java to print the

// given pattern

class Pattern

{

public static void main (String args[])

{

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

{

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

{

if(j%2==1)

System.out.print("*");

else

System.out.print("#");

}

System.out.println();

}

}

}

LIKE AS MUCH AS MUCH CAN!!!!

Answered by anindyaadhikari13
6

Question:-

Write a program in Java to print the following pattern.

*

*#

*#*

*#*#

Program:-

Here is your program in Java.

import java.util.*;

class Pattern

{

public static void main(String args[])

{

Scanner sc = new Scanner(System.in);

System.out.print("Enter the number of rows for the pattern: ");

int n=sc.nextInt();

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

{

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

{

if(j%2==1)

System.out.print("* ");

else

System.out.print("# ");

}

System.out.println();

}

}

}

Similar questions