Search
Search titles only
By:
Search titles only
By:
Log in
Register
Search
Search titles only
By:
Search titles only
By:
Menu
Install the app
Install
Forums
New posts
All threads
Latest threads
New posts
Trending threads
Trending
Search forums
What's new
New posts
New ads
New profile posts
Latest activity
Free Ads
Latest reviews
Search ads
Members
Current visitors
New profile posts
Search profile posts
Contact us
Latest ads
Colombo
Red Hat Certified System Administrator (RHCSA) - RHEL 10
Sanjeewani95
Updated:
Friday at 7:43 PM
NURSING , CAREGIVER , HOTEL & BEAUTY COURSES
IVA Para Medical Campus
Updated:
Thursday at 9:24 AM
Handmade Character Soft Toys Peppa Pig Family
anil1961
Updated:
Wednesday at 9:58 PM
Ad icon
Video Content Creator
pramukag
Updated:
Jun 28, 2026
Ad icon
QA Engineer Intern
pramukag
Updated:
Jun 28, 2026
Electronics
Vehicles
Property
Search
Reply to thread
Forums
General
Education
Thread for Programming and Realeted Topics
Get the App
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Message
<blockquote data-quote="rclakmal" data-source="post: 5588175" data-attributes="member: 98858"><p>elaz macho !!!!! digatama touch eke idapan !!!!</p><p></p><p>Machan <strong>MADHURA</strong> i think u were right in the above matter .First of all i should say that the above code doesn't provide a diamond .Actually in that "yahoo answer " problem ,i saw the output as a a triangle ......and i didnt read the whole question .....(may be an error in loading the web page) then i started coding as an idiot <img src="/styles/default/xenforo/smilies/default/P.gif" class="smilie" loading="lazy" alt=":P" title=":P :P" data-shortname=":P" /> and finally copy pasted the question and my answer here..........but only after reading this thread again i saw it was asked to design a DIAMOND output .<img src="/styles/default/xenforo/smilies/default/D.gif" class="smilie" loading="lazy" alt=":D" title="Big grin :D" data-shortname=":D" /> .........and then i tried to achieve that particular output,diamond.!!!! as u have mentioned i couldn't get the real shape !!! The reason should be that .Thanks for your contribution. </p><p></p><p>here is the updated code </p><p>[code]</p><p>package diamond;</p><p>import java.util.Scanner;</p><p></p><p>/**</p><p> *</p><p> * @author lakmal</p><p> */</p><p>class Diamond {</p><p></p><p> /**</p><p> * @param args the command line arguments</p><p> */</p><p> static int height;</p><p> static char state;</p><p> Diamond(int height){</p><p> for (int i=1;i<=height;i++){</p><p> if (i<=(height+1)/2){</p><p> for (int j=1;j<=i;j++){</p><p> </p><p> for (int k=1;k<=((height+1)/2)-i;k++){</p><p> System.out.print(" ");</p><p> }</p><p> </p><p> System.out.print(" *");</p><p> }</p><p> }</p><p> </p><p> else {</p><p> for(int j=1;j<=(height+1-i);j++){</p><p> for (int k=1;k<=i-((height+1)/2);k++){</p><p> System.out.print(" ");</p><p> }</p><p> System.out.print(" *");</p><p></p><p></p><p> }</p><p> }</p><p> </p><p> System.out.println();</p><p> }</p><p> }</p><p> </p><p></p><p> public static void main(String[] args) {</p><p> // TODO code application logic here</p><p> Scanner input=new Scanner(System.in);</p><p> do{</p><p></p><p> do{</p><p> System.out.println("Enter your height");</p><p> height=input.nextInt();</p><p> Diamond d1=new Diamond(height);</p><p> } while(height%2!=0);</p><p> System.out.println("Enter a odd number!!");</p><p> System.out.println("Do you want to continue?(y/n)");</p><p> state=input.next().charAt(0);</p><p></p><p></p><p></p><p> } while(state=='y');</p><p></p><p> }</p><p>}</p><p>[/code]</p></blockquote><p></p>
[QUOTE="rclakmal, post: 5588175, member: 98858"] elaz macho !!!!! digatama touch eke idapan !!!! Machan [B]MADHURA[/B] i think u were right in the above matter .First of all i should say that the above code doesn't provide a diamond .Actually in that "yahoo answer " problem ,i saw the output as a a triangle ......and i didnt read the whole question .....(may be an error in loading the web page) then i started coding as an idiot :P and finally copy pasted the question and my answer here..........but only after reading this thread again i saw it was asked to design a DIAMOND output .:D .........and then i tried to achieve that particular output,diamond.!!!! as u have mentioned i couldn't get the real shape !!! The reason should be that .Thanks for your contribution. here is the updated code [code] package diamond; import java.util.Scanner; /** * * @author lakmal */ class Diamond { /** * @param args the command line arguments */ static int height; static char state; Diamond(int height){ for (int i=1;i<=height;i++){ if (i<=(height+1)/2){ for (int j=1;j<=i;j++){ for (int k=1;k<=((height+1)/2)-i;k++){ System.out.print(" "); } System.out.print(" *"); } } else { for(int j=1;j<=(height+1-i);j++){ for (int k=1;k<=i-((height+1)/2);k++){ System.out.print(" "); } System.out.print(" *"); } } System.out.println(); } } public static void main(String[] args) { // TODO code application logic here Scanner input=new Scanner(System.in); do{ do{ System.out.println("Enter your height"); height=input.nextInt(); Diamond d1=new Diamond(height); } while(height%2!=0); System.out.println("Enter a odd number!!"); System.out.println("Do you want to continue?(y/n)"); state=input.next().charAt(0); } while(state=='y'); } } [/code] [/QUOTE]
Insert quotes…
Verification
Haya warak paha keeyada? (haya wadi kireema paha)
Post reply
Top
Bottom