wap in java : Void pattern (char ch): Print the following pattern with the given character, if ch = ‘*’ then the patter is –
* * * * *
* * * *
* * *
* *
*
* *
* * *
* * * *
* * * * *
Answers
Answered by
2
Answer:
public class Pattern
{
public static void main(String[] args)
{
int n=20;
int k=n/2;
char c='a';
for(int i=1;i<n;i++)
{
if(i<n/2)
{
for(int j=k;j>=1;j--)
{
System.out.print(c);
}
k--;
System.out.println();
}
else if(k==1)
{
System.out.println(c);
k++;
}
else
{
for(int j=1;j<=k;j++)
{
System.out.print(c);
}
k++;
System.out.println();
}
}
}
}
Answered by
1
Answer:
void pattern(char ch) {
for (int i = 5; i >= 0; i--) {
for (int j = 0; j <= i; j++)
System.out.print(ch);
System.out.println();
}
for (int i = 0; i <= 5; i++) {
for (int j = 0; j <= i; j++)
System.out.print(ch);
System.out.println();
}
}
Similar questions