Welcome to Dream.In.Code
Getting Java Help is Easy!

Join 136,273 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 2,256 people online right now. Registration is fast and FREE... Join Now!




diamond help

 
Closed TopicStart new topic

diamond help

tgrsnpr
14 Oct, 2008 - 04:13 AM
Post #1

New D.I.C Head
*

Joined: 10 Oct, 2008
Posts: 11

I can't get my diamond to look like this:
-----------*
----------***
--------*****
------*******
-----*********
----***********
-----*********
------*******
-------*****
--------***
---------*
Mines look like this:
---------*
-------***
------*****
----*******
---*********
--**********
---********
----******
-----****
------**
The top part I got right, but the bottom of the diamond is wrong, like the bottom one ends with 2 but it supposed to end with 1. I don't know why. But when I try to do even numbers it comes out perfectly. But odd numbers are wrong.
CODE

    int num = keybd.nextInt();


    for (int row = 0; row <= num/2; row++) {
      for (int col = 1; col <= (num/2) - row; col++)
        System.out.print(" ");
      for (int mid = 1; mid <= (row*2) - 1; mid++)
        System.out.print("*");
        System.out.println();
    }        
    
    for (int row = 1; row <= (num/2); row++) {
      for (int col = 1; col <= row - 1; col++)
        System.out.print(" ");
      for (int mid = 1; mid <= num - (row*2) + 1; mid++)
        System.out.print("*");
        System.out.println();
    }    
  }
}


User is offlineProfile CardPM
+Quote Post

jjsaw5
RE: Diamond Help
14 Oct, 2008 - 04:21 AM
Post #2

I vill break you
Group Icon

Joined: 4 Jan, 2008
Posts: 1,393



Thanked: 6 times
Dream Kudos: 125
Expert In: HTML, CSS, Database,

My Contributions
Do not double post your questions.


Site Rules Read Them.
User is offlineProfile CardPM
+Quote Post

Closed TopicStart new topic
Time is now: 12/2/08 05:02AM

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month