import
java.util.Scanner;
public
class
DiamondPattern
{
public
static
void
main(String[] args) {
System.out
.print("Enter
the number of stars you want in diamond shape: ");
Scanner
scan = new
Scanner(System.in);
int
n = scan.nextInt();
System.out.println("Diamond
of Stars are \n");
for
(int
i = 1; i <= n; i++) {
for
(int
j = 0; j < (n - i); j++)
System.out.print("
");
for
(int
j = 1; j <= i; j++)
System.out.print("*");
for
(int
k = 1; k < i; k++)
System.out.print("*");
System.out.println();
}
for
(int
i = n - 1; i >= 1; i--) {
for
(int
j = 0; j < (n - i); j++)
System.out.print("
");
for
(int
j = 1; j <= i; j++)
System.out.print("*");
for
(int
k = 1; k < i; k++)
System.out.print("*");
System.out.println();
}
System.out.println();
}
}
import java.util.Scanner;
ReplyDeletepublic class DiamondPatternExample {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Please enter the pattern size odd number ");
int size = sc.nextInt();
int half= size/2+1;
for (int row = 1; row <=size; row++) {
if(row<=half){
for(int space = 1; space <=half-row; space++){
System.out.print(" ");
}
for (int star = 1; star <=row; star++) {
System.out.print("* ");
}
System.out.println();
}else{
for(int space = row-half; space >=1; space--){
System.out.print(" ");
}
for (int star = size-row; star >= 0; star--) {
System.out.print("* ");
}
System.out.println();
}
}
}
}
These are nice code but i want these code
ReplyDelete*
** **
*** ***
** **
*
How to Write this program to Print Star Pattern in Java
Really Nice Post to Print Star Pattern in Java Yesterday I visit this blog and i was found lots of helpful information from your side thanks for sharing updated and New Technology related Post.
DeleteNice post for printing Start Pattern Programs in Java
ReplyDeletethanks.
Really Nice Post to Print Star Pattern in Java Yesterday I visit this blog and i was found lots of helpful information from your side thanks for sharing updated and New Technology related Post.
ReplyDeleteThis article regarding Print Star Pattern in Java is common for every java learner and thanks for sharing above codes in java programming.
ReplyDelete* *
* * * *
* * * * * * * *
* * * * * * * * * * * * * * * *
Please give code for above pattern Print Triangle of Stars in Java
I would like to say that this blog really convinced me to do it! Thanks, very good post. pawn shop in buckeye az
ReplyDelete