3 Replies - 15408 Views - Last Post: 26 March 2011 - 10:01 PM Rate Topic: -----

#1 bucknut71  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 4
  • Joined: 19-May 07

Diamond program

Posted 11 September 2009 - 11:39 AM

I have a homework assignment that requires us to write a program that accepts only odd numbers from a user, and diplays a diamond shape made of asterisks. For example, if the user inputs 7, then the diamond will look like:

...........*
.........***
.......*****
.....*******
.......*****
.........***
...........*

I know to use the modulus to determine if the number is odd. Other than that, I'm lost. Any suggestions would be great. I'm new to this, so please go easy.

Is This A Good Question/Topic? 1
  • +

Replies To: Diamond program

#2 ayman_mastermind  Icon User is offline

  • human.setType("geek");
  • member icon

Reputation: 126
  • View blog
  • Posts: 1,860
  • Joined: 12-December 08

Re: Diamond program

Posted 11 September 2009 - 11:47 AM

You can search the code snippets on D.I.C to get what you need. Here is a snippet that demonstrates your need: http://www.dreaminco...snippet3368.htm

For next time you should note that we do not do for your homework assignments, you will have to show us your source code, or you will have to use google or the forum search to get what you need.

Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.

Please post like this: :code:

Thank you for helping us helping you

Have a good day :)
Was This Post Helpful? 0
  • +
  • -

#3 aadhar41  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 1
  • Joined: 26-March 11

Re: Diamond program

Posted 26 March 2011 - 09:53 PM

View Postbucknut71, on 11 September 2009 - 11:39 AM, said:

I have a homework assignment that requires us to write a program that accepts only odd numbers from a user, and diplays a diamond shape made of asterisks. For example, if the user inputs 7, then the diamond will look like:

...........*
.........***
.......*****
.....*******
.......*****
.........***
...........*

I know to use the modulus to determine if the number is odd. Other than that, I'm lost. Any suggestions would be great. I'm new to this, so please go easy.

here is a the simple for loop solution of u'r problem without error try to learn it by yourself it's easy as compair to other....it's error free ....
import javax.swing.*;
public class diamond
{
	public static void main(String args[])
	{
		int i=0,j,k,n;
		n=Integer.parseInt(JOptionPane.showInputDialog("\nEnter value "));
		for(k=1;k<=n;k++)
		{
			for(i=0;i<=n-k;i++)
			{
				System.out.print(" ");
			}
			for(j=1;j<=k;j++)
			{
				System.out.print("*");
			}
			for(j=1;j<=k-1;j++)
			{
				System.out.print("*");
			}
			System.out.println("");
		}
		for(k=1;k<=n;k++)
		{
			for(i=0;i<=k;i++)
			{
				System.out.print(" ");
			}
			for(i=1;i<=n-k;i++)
			{
				System.out.print("*");
			}
			for(j=0;j<=n-k-2;j++)
			{
				System.out.print("*");
			}
			System.out.print("\n");
		}
	}
}


Mod Edit:
:code:
Was This Post Helpful? 1
  • +
  • -

#4 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2873
  • View blog
  • Posts: 11,032
  • Joined: 15-July 08

Re: Diamond program

Posted 26 March 2011 - 10:01 PM

aadhar41, in the future, please use code tags -> :code:

Also, at DIC, we prefer helping and guiding a person to an eventual solution rather than just giving them a solution. That way, that person can walk out with knowing how to do something. Just keep that in mind.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1