Latest Tutorials| Questions and Answers|Ask Questions?|Site Map




Have Programming Question? Ask it here!
 
 
 


Ruby
Draw a diamond
1 Answer(s)      5 years and 4 months ago
Posted in : Java Beginners



Advertisement
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
diamond print
diamond print   print the pattern 1 2 3 4 5 6 7 8 9 10 11 12
Advertisements
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. Draw a shape: Choose Pen tool (P key
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
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
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
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
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
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
how to create this diamond structure with java. - Java Beginners
how to create this diamond structure with java.   * *** ***** * *** *** * ***** * *** *** * ***** * *** *** * ***** *** *   
I need to output number diamond using nested for loops.
I need to output number diamond using nested for loops.  How to i output this using nested for loops 1 131 13531 1357531 135797531 1357531 13531 131 1
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
Lottery Draw - Java Beginners
Java lottery program  Please send me an example for the Lottery Draw application in Java.Thanks in advance
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...; color and rounded rectangle tool (U key) to draw a rounded rectangle shape
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. Draw Circle: Choose any color and Ellipse Tool (U key) to draw a circle as given below. World Map: Capture a world map
Dynamic Line draw in JSp
Dynamic Line draw in JSp  In my application. I have one source selected from listbox and multiple targets selected from checkboxes. After submitting "next" button it should give me multiple lines drw from one source to respective
How to draw a house, draw a house, a house
How to draw a house       Use this example to draw a house in the photoshop, it has been...; color and Rectangle tool (U key) to draw a rectangle shape like a window. Go
How to draw a wall, draw a wall, a wall
How to draw a wall       Now we are going to teach you to draw a real wall by the photoshop, it is very easy by my this example. Select color: First take a new document and choose
How to draw pie chart in J2ME
How to draw pie chart in J2ME  Hi, I'm developing a program using J2ME and I want to draw a pie chart but it seems J2ME language hasn't available chart component like JFreeChart in Java! could any one help me how can I draw a pie
Draw bufferimage in jpanel using netbeans
Draw bufferimage in jpanel using netbeans  please i need urgent help. i have form which contains some fields generated in netbeans. how can i draw bufferimage in Jpanel that is inside the form. thanks
draw a sine wave using jsp
draw a sine wave using jsp  hai frds.. i need to draw a sine wave by using jsp.. the values X and Y co-ordinate is present in database i have fetch those values from that then display the sine wave graph according
How to draw a bullet spot on the car, draw a bullet spot on the car, draw a bullet spot
How to draw a bullet spot on the car       This example has a technique to draw a bullet spot... a car picture. Circle: Draw a circle with "5d6780" color
Canvas won't draw on composite (SWT)
Canvas won't draw on composite (SWT)  I can't get a canvas to draw on a composite with SWT. I've made the composite on a shell and given it a layout but the canvas won't draw the image. Please help me and bare with me because I'm
Write a Java applet to draw cylinder and pentagon shapes.
Write a Java applet to draw cylinder and pentagon shapes.  Write a Java applet to draw cylinder and pentagon shapes
Draw graph using jsp without database connection
Draw graph using jsp without database connection  Draw graph using jsp code without database connection
Draw a line in a JPanel with button click in Java
Draw a line in a JPanel with button click in Java  Draw a line in a JPanel with button click in Java
How to draw in jPanel? swing/graphics Java
How to draw in jPanel? swing/graphics Java  How to draw in jPanel? (swing/graphics Java
Draw a Flowchart
Draw a Flowchart       This section illustrates you how to draw a Flowchart to compute the sum of first 50 natural numbers. To draw a flowchart, we have used
Draw Grids
Draw Grids       This section illustrates you how to draw grids. To draw the grids, we have defined rows and columns. The method g.drawLine(0, k * heightOfRow, width, k
how to draw lines,circles, rectangles on JSP.
how to draw lines,circles, rectangles on JSP.  how to draw lines,circles, rectangles on JSP. Kindly provide solutions asap
how to draw network with nodes - Java Beginners
how to draw network with nodes  how can i draw a network graph (game theory) with 3 nodes and each node display some information
Draw String Using Canvas
Draw String Using Canvas       This example is used to draw string on different location which is shown in figure. The given code is used to show, how to draw string at different
How to draw a circle bucket, draw a circle bucket, circle bucket
How to draw a circle bucket     ... style: Go to Layer menu > Layer style > Bevel and emboss. Draw Circle: Now draw a circle inside the big circle with any color as you like.  
draw the running or moving graph using database in jsp
draw the running or moving graph using database in jsp  hi my question is how to draw the running or moving graph using jsp and take x and y co-ordinate value from database
draw the running or moving graph using database in jsp
draw the running or moving graph using database in jsp  hi my question is how to draw the running or moving graph using jsp and take x and y co-ordinate value from database
How to draw a web button, draw a web button, web button
How to draw a web button       Be ready to learn a simple technique to draw a web button, if you.... Draw a circle: Choose Ellipse tool (U key) and drag a circle with "
Draw An Arc in Graphics
Draw An Arc in Graphics       In this section, you will learn how to draw an arc in Graphics. An arc of a circle is a segment of the circumference of the circle. To draw an arc
Draw Line in J2me
Draw Line in J2me       In this example we are going to show you how to draw a line using J2ME. Please... and class to draw a line.  Basically in J2ME, Canvas class is used to draw
How to draw a soccer boll
How to draw a soccer boll Draw a soccer boll by using...; . Polygonal Shape: Draw a shape with Black color... and draw again a polygonal shape. Define Pattern: Convert this file
Draw a Triangle using a Line2D
Draw a Triangle using a Line2D       This section illustrates you how to draw a triangle using a Line2D. To draw a triangle, we are using Line2D class of package java.awt.geom.
four rectangle/image of the shape of the button.then Draw these on some x and y co-ordinated in j2me then how to draw ?
four rectangle/image of the shape of the button.then Draw these on some x and y co-ordinated in j2me then how to draw ?  hi, i have button use... of the shape of the button.then Draw these on some x and y co-ordinated in j2me
Draw Ellipse in Rectangle
Draw Ellipse in Rectangle       This section illustrates you how to draw ellipse inside the rectangle. To draw an Ellipse inside the rectangle, we have defined two classes
Draw Calendar in SWT
Draw Calendar in SWT       This section illustrates you how to draw  a calendar in SWT, showing current date. SWT allows to create Calendar by using the java.util.Calendar class
 

 

 

DMCA.com