Write a program in java to print a Diamond pattern using (*) symbol. 【Use Scanner】
Answers
★ Java program to print Diamond Pattern:-
import java.util.*;
public class Diamond
{
public static void main(String[] args)
{
//
Scanner sc = new Scanner(System.in);
//
System.out.println("Enter the number of Rows:-");
int r= sc.nextInt();
System.out.println("##Pattern:-");
for (int a=1; a<=r; a++)
{
//
for (int b=r; b>a; b--)
{
System.out.print(" ");
}
//
for (int c=1; c<=(a * 2) -1; c++)
{
System.out.print("*");
}
System.out.println();
}
for (int a=r-1; a>=1; a--)
{
//
for (int b=r-1; b>=a; b--)
{
System.out.print(" ");
}
//
for (int c=1; c<=(a * 2) -1; c++)
{
System.out.print("*");
}
System.out.println();
}
sc.close();
}
}
★ Refer attachment for Output.
★ Input value in above Output is 10.