*
***
*****
***
*
print this pattern using java
Answers
Answered by
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
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
English,
5 months ago
Math,
5 months ago
Hindi,
11 months ago
Social Sciences,
1 year ago
Math,
1 year ago