write a program in java to display following patterns
Attachments:
Answers
Answered by
1
Answer:
program for option b
import java.util.Scanner;
public class Pattern {
public static void main(String[] args)
{
int i,j,r;
System.out.print("Input number of rows (half of the diamond) : ");
Scanner in = new Scanner(System.in);
r = in.nextInt();
for(i=0;i<=r;i++)
{
for(j=1;j<=r-i;j++)
System.out.print(" ");
for(j=1;j<=2*i-1;j++)
System.out.print("a");
System.out.print("\n");
}
for(i=r-1;i>=1;i--)
{
for(j=1;j<=r-i;j++)
System.out.print(" ");
for(j=1;j<=2*i-1;j++)
System.out.print("a");
System.out.print("\n");
}
}
}
Similar questions
Math,
6 months ago
Social Sciences,
6 months ago
Social Sciences,
6 months ago
Sociology,
11 months ago
English,
11 months ago
Physics,
1 year ago
Math,
1 year ago