943,626 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 1676
  • Java RSS
You are currently viewing page 1 of this multi-page discussion thread
Jun 28th, 2009
0

half diamond output in java

Expand Post »
hi im having problem on how to make the output of my programme like this:
if you enter a number: (EVEN)
*
**
***
*****
If you enter a numberODD)

*****
****
***
**
*
im always having an output of:
(EVEN)
*
**
***
****

(ODD)
*****
****
***
**
*
I hope somebody will haelp me:
here is my code:

import java.io.*;


public class del
{
public static void main(String[]args)throws IOException
{


BufferedReader IN = new BufferedReader(new InputStreamReader(System.in));
int a, c, d;
String b, e, f;

do{
System.out.println("Enter name:");
f = IN.readLine();
System.out.println("Enter a number:");
b = IN.readLine();
d = Integer.parseInt(b);

if(d%2==0)
{

for(a=d;a>=0;a--)
{


for(c=a;c<d;c++)
{
System.out.print(f);

}

System.out.println(" ");
}

}
else
{

for(a=0;a<=d;a+=1)
{

for(c=a;c<d;c++)
{
System.out.print(f);
}

System.out.println(" ");
}

}

System.out.print("Try Again?:");

e = IN.readLine();

}while(e.charAt(0)=='y'||e.charAt(0)=='Y');




}
}
Similar Threads
Reputation Points: 2
Solved Threads: 0
Newbie Poster
sympatiko is offline Offline
8 posts
since Jun 2009
Jun 28th, 2009
0

Re: half diamond output in java

Welcome sympatiko.

Use BB code tags. Your source code must be surrounded with bb code tags. Read How to wrap up source code with bb code tags?

You are near to the solution. Keep it up.
Moderator
Reputation Points: 2136
Solved Threads: 1228
Posting Genius
adatapost is offline Offline
6,527 posts
since Oct 2008
Jun 28th, 2009
0

Re: half diamond output in java

Click to Expand / Collapse  Quote originally posted by adatapost ...
Welcome sympatiko.

Use BB code tags. Your source code must be surrounded with bb code tags. Read How to wrap up source code with bb code tags?

You are near to the solution. Keep it up.
im a newbie in programming,,i cant understand those kind of coding,,can you please solve my problem if you know?
Reputation Points: 2
Solved Threads: 0
Newbie Poster
sympatiko is offline Offline
8 posts
since Jun 2009
Jun 28th, 2009
0

Re: half diamond output in java

Input a number and if it is odd then make it even.
Moderator
Reputation Points: 2136
Solved Threads: 1228
Posting Genius
adatapost is offline Offline
6,527 posts
since Oct 2008
Jun 28th, 2009
0

Re: half diamond output in java

Click to Expand / Collapse  Quote originally posted by sympatiko ...
im a newbie in programming,,i cant understand those kind of coding,,can you please solve my problem if you know?
The request to use code tags has nothing to do with programming ability; code tags are required because all spacing/formatting is stripped out when you do not use them. Your code is unreadable without them, and more important, your asterisk patterns are unreadable because all spaces are stripped without code tags.


[code]
// paste code or pattern here
[/code]


Note the difference (with code tags):

Java Syntax (Toggle Plain Text)
  1. *
  2. *
  3. *
  4. *

Without code tags:

*
*
*
*


Please repost using code tags, as explained above. Again, do this to retain spacing. Thanks.



[code]
// paste code or pattern here
[/code]
Featured Poster
Reputation Points: 2614
Solved Threads: 687
Posting Expert
VernonDozier is offline Offline
5,372 posts
since Jan 2008
Jul 3rd, 2009
0

Re: half diamond output in java

Click to Expand / Collapse  Quote originally posted by sympatiko ...
hi im having problem on how to make the output of my programme like this:
if you enter a number: (EVEN)
*
**
***
*****
If you enter a numberODD)

*****
****
***
**
*
im always having an output of:
(EVEN)
*
**
***
****

(ODD)
*****
****
***
**
*
I hope somebody will haelp me:
here is my code:

import java.io.*;


public class del
{
public static void main(String[]args)throws IOException
{


BufferedReader IN = new BufferedReader(new InputStreamReader(System.in));
int a, c, d;
String b, e, f;

do{
System.out.println("Enter name:");
f = IN.readLine();
System.out.println("Enter a number:");
b = IN.readLine();
d = Integer.parseInt(b);

if(d%2==0)
{

for(a=d;a>=0;a--)
{


for(c=a;c<d;c++)
{
System.out.print(f);

}

System.out.println(" ");
}

}
else
{

for(a=0;a<=d;a+=1)
{

for(c=a;c<d;c++)
{
System.out.print(f);
}

System.out.println(" ");
}

}

System.out.print("Try Again?:");

e = IN.readLine();

}while(e.charAt(0)=='y'||e.charAt(0)=='Y');




}
}
i mean the real output put must be
if even:
*
****
******

if odd:
******
****
*

so now,,give me the code,,how to make that
Reputation Points: 2
Solved Threads: 0
Newbie Poster
sympatiko is offline Offline
8 posts
since Jun 2009
Jul 3rd, 2009
0

Re: half diamond output in java

Click to Expand / Collapse  Quote originally posted by sympatiko ...
i mean the real output put must be
if even:
*
****
******

if odd:
******
****
*

so now,,give me the code,,how to make that
i mean half diamond,,not a right triangle
Reputation Points: 2
Solved Threads: 0
Newbie Poster
sympatiko is offline Offline
8 posts
since Jun 2009
Jul 3rd, 2009
0

Re: half diamond output in java

Use bb code tag. Read this - How to use code tag?
Moderator
Reputation Points: 2136
Solved Threads: 1228
Posting Genius
adatapost is offline Offline
6,527 posts
since Oct 2008
Jul 3rd, 2009
-1

Re: half diamond output in java

i want a quick solution man
Reputation Points: 2
Solved Threads: 0
Newbie Poster
sympatiko is offline Offline
8 posts
since Jun 2009
Jul 3rd, 2009
0

Re: half diamond output in java

Java Syntax (Toggle Plain Text)
  1. import java.io.*;
  2.  
  3.  
  4. public class p
  5. {
  6. public static void main(String[]args)throws IOException
  7. {
  8.  
  9. BufferedReader IN = new BufferedReader(new
  10.  
  11. InputStreamReader(System.in));
  12. int a, c, d,cnt;
  13. String b, e, f;
  14.  
  15. do{
  16. System.out.println("Enter name:");
  17. f = IN.readLine();
  18. System.out.println("Enter a number:");
  19. b = IN.readLine();
  20. d = Integer.parseInt(b);
  21. if(d%2==0)
  22. {
  23. for(a=1;a<=d;a++)
  24. {
  25. if(a==1)
  26. cnt=1;
  27. else
  28. cnt=a*2;
  29. for(c=1;c<=cnt;c++)
  30. {
  31. System.out.print(f);
  32. }
  33. System.out.println(" ");
  34. }
  35. }
  36. else
  37. {
  38. for(a=d;a>=1;a--)
  39. {
  40. if(a==1)
  41. cnt=1;
  42. else
  43. cnt=a*2;
  44. for(c=1;c<=cnt;c++)
  45. {
  46. System.out.print(f);
  47. }
  48. System.out.println(" ");
  49. }
  50. }
  51. System.out.print("Try Again?:");
  52. e = IN.readLine();
  53. }while(e.charAt(0)=='y'||e.charAt(0)=='Y');
  54. }
  55. }
Moderator
Reputation Points: 2136
Solved Threads: 1228
Posting Genius
adatapost is offline Offline
6,527 posts
since Oct 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Help needed to develop an application
Next Thread in Java Forum Timeline: Need help with character movement on slanted surfaces





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC