# DIAMOND PATTERN PROGRAM ! !

Page 1 of 1

## 10 Replies - 15123 Views - Last Post: 29 September 2010 - 08:12 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=113996&amp;s=7ebe62e128146adb1a786ac8697fcb15&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 *sunshine*

Reputation: 0
• Posts: 3
• Joined: 09-July 09

# DIAMOND PATTERN PROGRAM ! !

Posted 09 July 2009 - 11:33 PM

guys, pls help me wid d diamond pattern ! ! ! ! !
I hav my project due next week . . . . . so HELP ! !

where integer arguement is n, where n=4

This post has been edited by *sunshine*: 09 July 2009 - 11:34 PM

Is This A Good Question/Topic? 0

## Replies To: DIAMOND PATTERN PROGRAM ! !

### #2 Tanira

Reputation: 10
• Posts: 102
• Joined: 30-May 09

## Re: DIAMOND PATTERN PROGRAM ! !

Posted 09 July 2009 - 11:37 PM

*sunshine*, on 9 Jul, 2009 - 10:33 PM, said:

guys, pls help me wid d diamond pattern ! ! ! ! !
I hav my project due next week . . . . . so HELP ! !

where integer arguement is n, where n=4

We need more info to go off and also we need to see a reasonable amount of work on your behalf. Those are the rules.

### #3 ronaldjames

Reputation: 4
• Posts: 42
• Joined: 29-June 09

## Re: DIAMOND PATTERN PROGRAM ! !

Posted 10 July 2009 - 12:11 AM

*sunshine*, on 10 Jul, 2009 - 12:33 PM, said:

I hav my project due next week . . . . . so HELP ! !

D.I.C's policy is to help.

But we need to see that you has put some effort from your side.

Try for that program.
If any error occures paste that code here in this forum.
Somebody will come up with ideas.

### #4 blues90

Reputation: -3
• Posts: 20
• Joined: 25-June 09

## Re: DIAMOND PATTERN PROGRAM ! !

Posted 10 July 2009 - 12:34 AM

LOL.. ..U didnt wrote any code for your assignment?? Try to do it by your own, and then ask D.I.C.. Must be helped by programmer at here..

### #5 *sunshine*

Reputation: 0
• Posts: 3
• Joined: 09-July 09

## Re: DIAMOND PATTERN PROGRAM ! !

Posted 10 July 2009 - 05:44 AM

this is what I wrote . . . . please tell me what's wrong in this :

class diamond
{
public static void main
{
int i , j , k, n = 24;

k=(n%2==0)? n-1:n;

for( i = 0 ; i < n/2 ; i++ )
{
for( j = 0 ; j < k / 2 - i ; j++ )
System.out.print(" ");

for ( j = 0 ; j < i * 2 + 1 ; j++ )
System.out.print("*");

System.out.println();
}

if( n % 2 != 0)
{
for( i = 0 ; i < n ; i++ )
System.out.print("*");

System.out.println();
}

for( i = n/2-1 ; i >= 0 ; i-- )
{
for( j = 0 ; j < k/2 - i ; j++ )
System.out.print(" ");

for( j = 0 ; j < i*2+1 ; j++ )
System.out.print("*");

System.out.println();
}
}
}

### #6 arsh_aarsh

Reputation: 6
• Posts: 36
• Joined: 13-October 08

## Re: DIAMOND PATTERN PROGRAM ! !

Posted 10 July 2009 - 06:07 AM

*sunshine*, on 10 Jul, 2009 - 04:44 AM, said:

this is what I wrote . . . . please tell me what's wrong in this :

class diamond
{
public static void main
{
int i , j , k, n = 24;

k=(n%2==0)? n-1:n;

for( i = 0 ; i < n/2 ; i++ )
{
for( j = 0 ; j < k / 2 - i ; j++ )
System.out.print(" ");

for ( j = 0 ; j < i * 2 + 1 ; j++ )
System.out.print("*");

System.out.println();
}

if( n % 2 != 0)
{
for( i = 0 ; i < n ; i++ )
System.out.print("*");

System.out.println();
}

for( i = n/2-1 ; i >= 0 ; i-- )
{
for( j = 0 ; j < k/2 - i ; j++ )
System.out.print(" ");

for( j = 0 ; j < i*2+1 ; j++ )
System.out.print("*");

System.out.println();
}
}
}

Can you please also post its output?

### #7 *sunshine*

Reputation: 0
• Posts: 3
• Joined: 09-July 09

## Re: DIAMOND PATTERN PROGRAM ! !

Posted 10 July 2009 - 06:26 AM

I couldnt get d output . . . . d program wouldnt compile only

### #8 jpav

Reputation: 3
• Posts: 29
• Joined: 08-July 09

## Re: DIAMOND PATTERN PROGRAM ! !

Posted 10 July 2009 - 08:22 AM

*sunshine*, on 10 Jul, 2009 - 04:44 AM, said:

this is what I wrote . . . . please tell me what's wrong in this :

To begin with, you have a fairly basic syntax problem to fix before you can get anywhere. "main" is a method and therefore must be followed by parentheses. It must also be defined to accept a single array of Strings as its only parameter.

Reputation:

## Re: DIAMOND PATTERN PROGRAM ! !

Posted 28 March 2010 - 12:04 AM

no () put after void main
the output is
*
***
*****
*******
*********
***********
*************
***************
*****************
*******************
*********************
***********************
***********************
*********************
*******************
*****************
***************
*************
***********
*********
*******
*****
***
*

Reputation:

## Re: DIAMOND PATTERN PROGRAM ! !

Posted 29 September 2010 - 07:38 AM

The programs works however he forgot to put (String []args)
i know this answer is too late but for other who might need it later
-----------------------------------------------------------------------
```class diamond
{
public static void main(String []args)
{
int i , j , k, n = 24;

k=(n%2==0)? n-1:n;

for( i = 0 ; i < n/2 ; i++ )
{
for( j = 0 ; j < k / 2 - i ; j++ )
System.out.print(" ");

for ( j = 0 ; j < i * 2 + 1 ; j++ )
System.out.print("*");

System.out.println();
}

if( n % 2 != 0)
{
for( i = 0 ; i < n ; i++ )
System.out.print("*");

System.out.println();
}

for( i = n/2-1 ; i >= 0 ; i-- )
{
for( j = 0 ; j < k/2 - i ; j++ )
System.out.print(" ");

for( j = 0 ; j < i*2+1 ; j++ )
System.out.print("*");

System.out.println();
}
}
}
```

This post has been edited by JackOfAllTrades: 29 September 2010 - 07:39 AM
Reason for edit:: Added code tags

### #11 Luckless

• </luck>

Reputation: 293
• Posts: 1,146
• Joined: 31-August 09

## Re: DIAMOND PATTERN PROGRAM ! !

Posted 29 September 2010 - 08:12 AM

Please don't post working solutions, as others might have the same assignment. While you guys found the problem, it is up to the OP to fix it. We are here to guide and prod in the right direction, but we are not supposed to give out something they can copy, paste, and turn in. Thanks for your time.