half diamond output in java

Reply

Join Date: Jun 2009
Posts: 8
Reputation: sympatiko has a little shameless behaviour in the past 
Solved Threads: 0
sympatiko sympatiko is offline Offline
Newbie Poster

half diamond output in java

 
0
  #1
Jun 28th, 2009
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');




}
}
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,552
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 452
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

Re: half diamond output in java

 
0
  #2
Jun 28th, 2009
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.
Failure is not fatal, but failure to change might be. - John Wooden
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 8
Reputation: sympatiko has a little shameless behaviour in the past 
Solved Threads: 0
sympatiko sympatiko is offline Offline
Newbie Poster

Re: half diamond output in java

 
0
  #3
Jun 28th, 2009
Originally Posted by adatapost View Post
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?
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,552
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 452
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

Re: half diamond output in java

 
0
  #4
Jun 28th, 2009
Input a number and if it is odd then make it even.
Failure is not fatal, but failure to change might be. - John Wooden
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,805
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 501
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

Re: half diamond output in java

 
0
  #5
Jun 28th, 2009
Originally Posted by sympatiko View Post
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):

  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]
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 8
Reputation: sympatiko has a little shameless behaviour in the past 
Solved Threads: 0
sympatiko sympatiko is offline Offline
Newbie Poster

Re: half diamond output in java

 
0
  #6
Jul 3rd, 2009
Originally Posted by sympatiko View 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');




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

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

so now,,give me the code,,how to make that
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 8
Reputation: sympatiko has a little shameless behaviour in the past 
Solved Threads: 0
sympatiko sympatiko is offline Offline
Newbie Poster

Re: half diamond output in java

 
0
  #7
Jul 3rd, 2009
Originally Posted by sympatiko View Post
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
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,552
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 452
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

Re: half diamond output in java

 
0
  #8
Jul 3rd, 2009
Use bb code tag. Read this - How to use code tag?
Failure is not fatal, but failure to change might be. - John Wooden
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 8
Reputation: sympatiko has a little shameless behaviour in the past 
Solved Threads: 0
sympatiko sympatiko is offline Offline
Newbie Poster

Re: half diamond output in java

 
-1
  #9
Jul 3rd, 2009
i want a quick solution man
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,552
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 452
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

Re: half diamond output in java

 
0
  #10
Jul 3rd, 2009
  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. }
Failure is not fatal, but failure to change might be. - John Wooden
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC