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




Have Programming Question? Ask it here!
 
 
 


bhaskarreddy
Diamond shape num
1 Answer(s)      4 years and 7 months ago
Posted in : Java Interview Questions


How To Print Diamond Shape Numbers I Want Logic?Using For loops?

Advertisement
View Answers

December 26, 2009 at 5:29 PM


Hi Friend,

Try the following code:

public class Diamond{
public static void main(String[] args){
int row = 5;
for(int i=1; i<(row/2+.5); i++ ){
for (int j=1; j<(row/2+1.5)-i; j++){
System.out.print(" ");
}
for(int c=0; c<(i*2)-1; c++)
System.out.print(c);
System.out.println();
}
for(int d=1; d<row+1; d++){
System.out.print(d);
}
System.out.println();
for(int i=1; i<(row/2+.5); i++ ){
for(int c=0;c<i; c++)
System.out.print(" ");
for(int j=1; j<row-(i*2)+1; j++){
System.out.print(j);
}
System.out.println();
}
}
}

Hope that it will be helpful for you.
Thanks


Related Tutorials/Questions & Answers:
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
shape looping
shape looping  can some1 help me?i have to make a shape using "*" by looping...and i dun know how...please and thank you * **   java diamond shape: public class Diamond{ public static void main(String[] args){ int
Advertisements
diamond print
diamond print   print the pattern 1 2 3 4 5 6 7 8 9 10 11 12
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
What is a Loose Diamond?
shrinking the diamond too much. After that you have the shape of a loose diamond... as the diamond shape. This is also the cheapest because it is the easiest to create...What is a Loose Diamond? Everyone knows what diamonds. Looking at them from
Shape - Java Beginners
Shape  Respected Sir, Please send me the code of diamond shape...... for diamond shape.   Hi friend I understand your problem, so that I am sending you coding for diamond shape.Please let me know for further help.Hope
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<
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
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 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
How to convert a picture into a shape, convert a picture into a shape, picture shape
How to convert a picture into a shape       If you want to use a picture shape but you are not able for that, don't worry. You will learn easily to convert a picture into shape. Take
Php Sql num rows
Php Sql num rows      .... In this example, we have created a num_rows.php file in which we executed a query..._num_rows() method.       Table:emp   Source Code
PDO Fetch Num
PDO Fetch Num: We've discussed in the previous tutorial about PDO::FETCH_ASSOC, similarly PDO provides another function which returns the numerical...;query($sql); $result=$stmt->fetch(PDO::FETCH_NUM); echo "<table
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
How to convert new paper into a man shape, convert new paper into a man shape, new paper into a man shape
How to convert new paper into a man shape   ... shape in this example. Take a new picture: Take a news paper picture, choose Polygonal lasso tool (L key) to make selection like a man shape
how to create this diamond structure with java. - Java Beginners
how to create this diamond structure with java.   * *** ***** * *** *** * ***** * *** *** * ***** * *** *** * ***** *** *   
Drawing a Shape in Excel Sheet
Drawing a Shape in Excel Sheet In this section, you will learn how to draw a shape in excel sheets using Apache POI library. Using Apache POI, you can draw a shape with the help of Microsoft Office drawing tools. The top-most shape
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
Create Shape in Excel Using JSP
create shape in excel using jsp    ...; and then after we create a shape. At excel sheet e.g. we are creating line in this example. To create shape we use setShapeType() in this method we are passing
Creating Auto Shape in PowerPoint Using Java
Creating Auto Shape in PowerPoint Using Java... to create auto shape on PowerPoint slide using java. In this example, we are creating the object of AutoShape .We are passing the shape type into AutoShape
Inserting Text on Shape Using Java
Inserting Text on Shape Using Java       In this example we are going to create auto shape... the object of AutoShape .We are passing the shape type into AutoShape as argument
find largest num enter by user using loop method - Java Interview Questions
find largest num enter by user using loop method  hi..it's me again.. thanks for answering my question.. i wanna ask, if i wanna use loop in the part: int a, b, c, d, e; Scanner in = new Scanner(System.in
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
i have installed oracle 10g (both ee and xe) editions... while am installing i found port num as 1521 for ee, 1522 for xe
i have installed oracle 10g (both ee and xe) editions... while am installing i found port num as 1521 for ee, 1522 for xe  i have installed oracle 10g (both ee and xe) editions... while am installing i found port num as 1521
Num Sum
Num Sum       Easy, Sharable Web Spreadsheets, like google spreadsheets. Great for teams, clubs & your crew,Track all your group data together,Easy and super simple to use Read full
Php Sql num rows
Php Sql num rows This example illustrates how to find number of rows... and find the number of rows of the table by mysql_num_rows methods. The output... of num_rows.php  <?php   $link 
Create cube shape in Applet
Create cube shape in Applet In this tutorial, you will learn how to create a cube using java2d. The example creates a cube which gives a 3d view to the cube. Here we haven't used java3d packages. The cube can be rotate when
Creating Shapes using Shape Groups
Creating Shapes using Shape Groups In this section, you will learn how to create shapes using Apache POI library. EXAMPLE import... = (HSSFPatriarch) sheet .createDrawingPatriarch(); // Create a shape group
Create Round Button in Java swing
a button of round shape. Java2D APIs and Java Swing make it easy to implement..., then add code to set the shape you want to give. Finally override the paintComponent() and paintBorder() methods to render the shape. Example: import
sahabaj
sahabaj  diamond shape pattern print of numbers 123456789101112131415987654321
Java create triangle pattern
Java create triangle pattern In this tutorial, you will learn how to create a triangle shape. For this, user is allowed to enter number of lines to display the triangle of that length and a symbol to show the triangle in a particular
Simple Basic Stroke Example
stroke.  The stylistic representation of the outline for the specified shape has been given by the interface Stroke. To outline the specified shape rendered... the shape. The float value pass into the constructor of class BasicStroke shows
recursion method - Ajax
in the diamond shape recursion method   Hi friend, Code for solving...( int num ) { int pre = num/2; for (int i=1; i<=(num/2)+2; i+=2,pre-- ) { line( pre, i ); } for (int i=num; i>=(num/2)-2; i-=2,pre
PHP SQL Number of Rows
. To understand how to count the number of rows in a table, we have created a sql_num_rows.php...;). The number of rows are returned by the mysql_num_rows() method.       Table: users   Source Code of sql_num_rows.php 
Write a program to construct a triangle with the ?*?
programming will teach you the coding for constructing a shape of triangle by using... any number on your command window and surely you will get a triangle shape
Show Rotation property of class AffineTransform
property. To show rotation, we have used Ellipse2D class to draw the shape oval...); The method draw(shape) draws the specified shape in the original location defined... for the specified shape has been given by the interface Stroke. To outline
Use Alpha values to draw in Layers
values to the draw the specific shape in layers. An alpha object produces the alpha..., objects are invisible. As the intensity decreases, the specific shape becomes... (350,300) is created. The g.fillOval() fills the oval shape with the color defined
Move Curve Control Point
control point and manipulates the shape of curve. The Control points are the points on a curve which are used to change the shape and angle of the curve. On stretching and rotating the control point, the shape of the curve and the angle
How to design a text button.
How to design a text button.       With this tutorial you will be able to learn a design of the text button, mostly we use simple buttons of circle and rectangle shape
How to Create Circle In Java
. It describes a shape. But the Java 2D definition of a shape does not require the shape to enclose an area. The Java2D API  also provides several classes
Clip of image
. To show the image clip, we have used Ellipse2D class to show the oval shape.... To give the stylistic and impressive outline of the specified shape, class...;private double p, q;   private double ip 
 

 

 

DMCA.com