Computer Science, asked by bishtdiya16, 11 months ago

*
***
*****
***
*
print this pattern using java

Answers

Answered by ram14423
0

Answer:

import java.util.*;

public class nested

{public static void main(String args[]);

{int i,j;

for(i=0;i<=5;i++)

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

if(j>=5)

j-=2;

}

System.out.println("*");

}}

Answered by anindyaadhikari13
1

Question:-

Write a program in Java to display the following pattern.

*

***

*****

***

*

Program:-

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++)

System.out.print("* ");

System.out.println();

}

for(int i=n-1;i>=1;i--)

{

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

System.out.print("* ");

System.out.println();

}

}

}

Similar questions