Computer Science, asked by shreya5677, 6 months ago

Write a program in java to print a Diamond pattern using (*) symbol. 【Use Scanner】​

Answers

Answered by Bᴇʏᴏɴᴅᴇʀ
7

Java program to print Diamond Pattern:-

\pink{\bigstar} \large{\underline{\underline{\tt\purple{Code:-}}}}

import java.util.*;

public class Diamond

{

public static void main(String[] args)

{

// \sf\red{Creating \: a \: new \: Scanner \: object}

Scanner sc = new Scanner(System.in);

// \sf\red{Asking \: user \: to \: In{p}ut \: the \: number \: of \: rows}

System.out.println("Enter the number of Rows:-");

int r= sc.nextInt();

System.out.println("##Pattern:-");

for (int a=1; a<=r; a++)

{

// \sf\red{Printing \: space}

for (int b=r; b>a; b--)

{

System.out.print(" ");

}

// \sf\red{Printing \: star}

for (int c=1; c<=(a * 2) -1; c++)

{

System.out.print("*");

}

System.out.println();

}

for (int a=r-1; a>=1; a--)

{

// \sf\red{Printing \: space}

for (int b=r-1; b>=a; b--)

{

System.out.print(" ");

}

// \sf\red{Printing \: star}

for (int c=1; c<=(a * 2) -1; c++)

{

System.out.print("*");

}

System.out.println();

}

sc.close();

}

}

\pink{\bigstar} \large{\underline{\underline{\tt\purple{Out{p}ut:-}}}}

Refer attachment for Output.

Input value in above Output is 10.

Attachments:

pandaXop: Nice ☃️
Similar questions