Draw a diamond

Draw a diamond

View Answers

January 17, 2009 at 12:52 AM

Hi friend,

Code to help solve the problem :

import java.util.*;
public class Diamond
{
static Scanner console=new Scanner(System.in);
public static void main(String[]args)
{
int noOfstarlines;
int counter;
System.out.println("Enter the number of star lines");
noOfstarlines=console.nextInt();
for(counter=1;counter<=noOfstarlines;counter++)
{
printStars(counter);
}
}

public static void printStars(int size)
{
int i,j,k,l,m,n;
System.out.println("size " +size);

for(i=1;i<=size;i++)
{
for(k=1;k<=size-i;k++)
{
System.out.print(" ");
}
for(j=1;j<=i;j++)
{
System.out.print("*");
}
for(j=1;j<=i-1;j++)
{
System.out.print("*");
}
System.out.println();
}
for(i=size-1;i>=1;i--)
{
for(k=1;k<=size-i;k++)
{
System.out.print(" ");
}
for(j=1;j<=i;j++)
{
System.out.print("*");
}
for(j=1;j<=i-1;j++)
{
System.out.print("*");
}
System.out.println();
}


}
}

Thanks









Related Tutorials/Questions & Answers:
Draw a diamond - Java Beginners
Draw a diamond  I want to draw a diamond shapein java using (*) in 9 lines. Here is the code import java.util.*; public class Diamond { static... the problem : import java.util.*; public class Diamond { static Scanner
How to make a diamond necklace, make a diamond necklace, diamond necklace
How to make a diamond necklace       This tutorial will give you instruction to make draw a diamond... file with black background file as here.ADS_TO_REPLACE_1 Draw a shape: Choose
Advertisements
diamond print
diamond print   print the pattern 1 2 3 4 5 6 7 8 9 10 11 12
ModuleNotFoundError: No module named 'diamond'
ModuleNotFoundError: No module named 'diamond'  Hi, My Python... 'diamond' How to remove the ModuleNotFoundError: No module named 'diamond... to install padas library. You can install diamond python with following command
ModuleNotFoundError: No module named 'diamond'
ModuleNotFoundError: No module named 'diamond'  Hi, My Python... 'diamond' How to remove the ModuleNotFoundError: No module named 'diamond... to install padas library. You can install diamond python with following command
ModuleNotFoundError: No module named 'diamond'
ModuleNotFoundError: No module named 'diamond'  Hi, My Python... 'diamond' How to remove the ModuleNotFoundError: No module named 'diamond... to install padas library. You can install diamond python with following command
Draw Line
Draw Line  sir i want to draw a moving line in j2me.That line should also show arrow in moving direction. How can we do so
ModuleNotFoundError: No module named 'appenlight-diamond'
ModuleNotFoundError: No module named 'appenlight-diamond'  Hi, My... named 'appenlight-diamond' How to remove the ModuleNotFoundError: No module named 'appenlight-diamond' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'diamond-accounting'
ModuleNotFoundError: No module named 'diamond-accounting'  Hi, My... named 'diamond-accounting' How to remove the ModuleNotFoundError: No module named 'diamond-accounting' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'diamond-next'
ModuleNotFoundError: No module named 'diamond-next'  Hi, My Python... 'diamond-next' How to remove the ModuleNotFoundError: No module named 'diamond-next' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'diamond-next'
ModuleNotFoundError: No module named 'diamond-next'  Hi, My Python... 'diamond-next' How to remove the ModuleNotFoundError: No module named 'diamond-next' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'diamond-patterns'
ModuleNotFoundError: No module named 'diamond-patterns'  Hi, My... named 'diamond-patterns' How to remove the ModuleNotFoundError: No module named 'diamond-patterns' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'diamond-patterns'
ModuleNotFoundError: No module named 'diamond-patterns'  Hi, My... named 'diamond-patterns' How to remove the ModuleNotFoundError: No module named 'diamond-patterns' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'Flask-Diamond'
ModuleNotFoundError: No module named 'Flask-Diamond'  Hi, My... 'Flask-Diamond' How to remove the ModuleNotFoundError: No module named 'Flask-Diamond' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'Puppet-Diamond'
ModuleNotFoundError: No module named 'Puppet-Diamond'  Hi, My... named 'Puppet-Diamond' How to remove the ModuleNotFoundError: No module named 'Puppet-Diamond' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'Puppet-Diamond'
ModuleNotFoundError: No module named 'Puppet-Diamond'  Hi, My... named 'Puppet-Diamond' How to remove the ModuleNotFoundError: No module named 'Puppet-Diamond' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'Puppet-Diamond'
ModuleNotFoundError: No module named 'Puppet-Diamond'  Hi, My... named 'Puppet-Diamond' How to remove the ModuleNotFoundError: No module named 'Puppet-Diamond' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'Puppet-Diamond'
ModuleNotFoundError: No module named 'Puppet-Diamond'  Hi, My... named 'Puppet-Diamond' How to remove the ModuleNotFoundError: No module named 'Puppet-Diamond' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'pytest-diamond'
ModuleNotFoundError: No module named 'pytest-diamond'  Hi, My... named 'pytest-diamond' How to remove the ModuleNotFoundError: No module named 'pytest-diamond' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'sf-diamond'
ModuleNotFoundError: No module named 'sf-diamond'  Hi, My Python... 'sf-diamond' How to remove the ModuleNotFoundError: No module named 'sf-diamond' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'spud-diamond'
ModuleNotFoundError: No module named 'spud-diamond'  Hi, My Python... 'spud-diamond' How to remove the ModuleNotFoundError: No module named 'spud-diamond' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'whale-diamond'
ModuleNotFoundError: No module named 'whale-diamond'  Hi, My... 'whale-diamond' How to remove the ModuleNotFoundError: No module named 'whale-diamond' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'whale-diamond'
ModuleNotFoundError: No module named 'whale-diamond'  Hi, My... 'whale-diamond' How to remove the ModuleNotFoundError: No module named 'whale-diamond' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'Agile-Diamond'
ModuleNotFoundError: No module named 'Agile-Diamond'  Hi, My... 'Agile-Diamond' How to remove the ModuleNotFoundError: No module named 'Agile-Diamond' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'appenlight-diamond'
ModuleNotFoundError: No module named 'appenlight-diamond'  Hi, My... named 'appenlight-diamond' How to remove the ModuleNotFoundError: No module named 'appenlight-diamond' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'diamond-accounting'
ModuleNotFoundError: No module named 'diamond-accounting'  Hi, My... named 'diamond-accounting' How to remove the ModuleNotFoundError: No module named 'diamond-accounting' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'diamond-next'
ModuleNotFoundError: No module named 'diamond-next'  Hi, My Python... 'diamond-next' How to remove the ModuleNotFoundError: No module named 'diamond-next' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'diamond-patterns'
ModuleNotFoundError: No module named 'diamond-patterns'  Hi, My... named 'diamond-patterns' How to remove the ModuleNotFoundError: No module named 'diamond-patterns' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'Flask-Diamond'
ModuleNotFoundError: No module named 'Flask-Diamond'  Hi, My... 'Flask-Diamond' How to remove the ModuleNotFoundError: No module named 'Flask-Diamond' error? Thanks   Hi, In your python
Java draw triangle draw method?
Java draw triangle draw method?  hi how would i construct the draw method for an triangle using the 'public void draw (graphics g ) method? im... a rectangle and this works for a rectangle: public void draw(Graphics g
Diamond Jewelry
Diamond Jewelry Everyone loves diamonds, especially ladies, because besides... a lot more comfortable in special situations. Basically, diamond jewelry... the cheapest diamond jewelry items, you are making a statement. Don't get us
DIAMOND PROGRAM - Java Interview Questions
DIAMOND PROGRAM  I Want Print Diamond ?I Want Code?plz help me  Hi Friend, Try the following code: public class PrintDiamond { public static void main(String[] args) { int n = 5; for (int i = -n
What is a Loose Diamond?
What is a Loose Diamond? Everyone knows what diamonds. Looking at them from... precious metals. So you know what diamonds are, but what is a loose diamond? A loose diamond is virtually the same, but it has not been used in any piece
ModuleNotFoundError: No module named 'diamond-add-taxonomy'
ModuleNotFoundError: No module named 'diamond-add-taxonomy'  Hi...: No module named 'diamond-add-taxonomy' How to remove the ModuleNotFoundError: No module named 'diamond-add-taxonomy' error? Thanks   Hi
ModuleNotFoundError: No module named 'snap-plugin-collector-diamond'
ModuleNotFoundError: No module named 'snap-plugin-collector-diamond'  ...: No module named 'snap-plugin-collector-diamond' How to remove the ModuleNotFoundError: No module named 'snap-plugin-collector-diamond' error
ModuleNotFoundError: No module named 'cloudify-diamond-plugin'
ModuleNotFoundError: No module named 'cloudify-diamond-plugin'  Hi...: No module named 'cloudify-diamond-plugin' How to remove the ModuleNotFoundError: No module named 'cloudify-diamond-plugin' error? Thanks   
ModuleNotFoundError: No module named 'diamond-add-taxonomy'
ModuleNotFoundError: No module named 'diamond-add-taxonomy'  Hi...: No module named 'diamond-add-taxonomy' How to remove the ModuleNotFoundError: No module named 'diamond-add-taxonomy' error? Thanks   Hi
ModuleNotFoundError: No module named 'diamond-add-taxonomy'
ModuleNotFoundError: No module named 'diamond-add-taxonomy'  Hi...: No module named 'diamond-add-taxonomy' How to remove the ModuleNotFoundError: No module named 'diamond-add-taxonomy' error? Thanks   Hi
draw chart in web application
draw chart in web application  how to draw bar chat from the record store in database? i.e. draw the bar chart according to selected record
ModuleNotFoundError: No module named 'draw'
ModuleNotFoundError: No module named 'draw'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'draw' How to remove the ModuleNotFoundError: No module named 'draw' error
ModuleNotFoundError: No module named 'draw'
ModuleNotFoundError: No module named 'draw'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'draw' How to remove the ModuleNotFoundError: No module named 'draw' error
ARRAY DIAMOND - Java Interview Questions
ARRAY DIAMOND  HI I WANT PRINT LIKE THIS I Want Print In Diamond Shape? 1 2 3 4 5 6 5 4 3 2 1 4 3 2 1 3 2 1 2 1 1 I WANT SOURCE CODE?  Hi Friend, Try the following code: class
Lottery Draw - Java Beginners
Java lottery program  Please send me an example for the Lottery Draw application in Java.Thanks in advance
DIAMOND PROGRAM 122 - Java Interview Questions
DIAMOND PROGRAM 122  I Want Print Exact Diamond Shape?I Want Code ?Plz Help Me?  Hi Friend, Try the following code: public class Diamond{ public static void main(String[] args){ int row = 7; for(int i=1; i<
Diamond shape num - Java Interview Questions
Diamond shape num  How To Print Diamond Shape Numbers I Want Logic?Using For loops?  Hi Friend, Try the following code: public class Diamond{ public static void main(String[] args){ int row = 5; for(int i=1
How to draw a television
How to draw a television Try to draw a television... Shape: First draw a Rectangle shape with black color by using Rectangle tool (U... and rounded rectangle tool (U key) to draw a rounded rectangle shape.ADS_TO_REPLACE_5
draw this pattern of swastic.
draw this pattern of swastic.  last time i had asked swastic pattern but u had used array i want use only for loop please not use array...(" "); }}} please draw this pattern with explation i.e for understand loop
draw this pattern of swastic.
draw this pattern of swastic.  last time i had asked swastic pattern but u had used array i want use only for loop please not use array...(" "); }}} please draw this pattern with explation i.e for understand loop
How to draw globe, draw globe, globe
How to draw globe      .... New File: Start by taking a new document.ADS_TO_REPLACE_1 Draw Circle: Choose any color and Ellipse Tool (U key) to draw a circle as given below. World Map
Fashion Diamond Accessories
Fashion Diamond Accessories Fashion diamond accessories come in many different... it is often difficult and time consuming to purchase fashion diamond accessories... that fashion diamond accessories cost a lot of money because of the diamonds

Ads