954,518 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

half diamond output in java

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 number:(ODD)

*****
****
***
**
*
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

sympatiko
Newbie Poster
8 posts since Jun 2009
Reputation Points: 2
Solved Threads: 0
 

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.

__avd
Posting Genius (adatapost)
Moderator
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
 

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?

sympatiko
Newbie Poster
8 posts since Jun 2009
Reputation Points: 2
Solved Threads: 0
 

Input a number and if it is odd then make it even.

__avd
Posting Genius (adatapost)
Moderator
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
 
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):

*
 *
  *
   *


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]

VernonDozier
Posting Expert
5,527 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 711
 

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 number:(ODD)

***** **** *** ** * 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 i mean the real output put must be if even: * **** ******

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

so now,,give me the code,,how to make that

sympatiko
Newbie Poster
8 posts since Jun 2009
Reputation Points: 2
Solved Threads: 0
 

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

sympatiko
Newbie Poster
8 posts since Jun 2009
Reputation Points: 2
Solved Threads: 0
 

Use bb code tag. Read this - How to use code tag?

__avd
Posting Genius (adatapost)
Moderator
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
 

i want a quick solution man

sympatiko
Newbie Poster
8 posts since Jun 2009
Reputation Points: 2
Solved Threads: 0
 
import java.io.*;


public class p
{
public static void main(String[]args)throws IOException
{
 
   BufferedReader IN = new BufferedReader(new 

InputStreamReader(System.in));
   int a, c, d,cnt; 
   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=1;a<=d;a++)
               {
                 if(a==1)
                  cnt=1;
                 else
                  cnt=a*2;
                 for(c=1;c<=cnt;c++)
                    {
                      System.out.print(f);
                    }
               System.out.println(" ");
           }
       }
    else
        {
         for(a=d;a>=1;a--)
             {
                 if(a==1)
                  cnt=1;
                 else
                  cnt=a*2;
               for(c=1;c<=cnt;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');
  }
}
__avd
Posting Genius (adatapost)
Moderator
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
 
i want a quick solution man

I want a million dollars. The answer is no. We don't give out free code to people who make absolutely no effort.

VernonDozier
Posting Expert
5,527 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 711
 
i want a quick solution man

Then you'd better get crackin'!

masijade
Industrious Poster
Moderator
4,253 posts since Feb 2006
Reputation Points: 1,471
Solved Threads: 494
 
I want a million dollars. The answer is no. We don't give out free code to people who make absolutely no effort.


what effor1 do you want for me??,,im 1 week trying for two projects,,this java is killing me

sympatiko
Newbie Poster
8 posts since Jun 2009
Reputation Points: 2
Solved Threads: 0
 
what effor1 do you want for me??,,im 1 week trying for two projects,,this java is killing me

Read my post 5 again. I told you exactly why you needed to use code tags around your diamond pattern and exactly how to do it. No one can make an sense of your diamond pattern if you don't use code tags because ALL SPACING IS STRIPPED OUT OF A POST THAT DOES NOT USE CODE TAGS!

Any pattern and any code needs to be in code tags for this reason. You refused to accommodate or even acknowledge this very simple request, plus you have a sense of entitlement that is very offputting. Hence your lack of effort. If you had used code tags, sentences like this would be unnecessary:i mean half diamond,,not a right triangle

because the spacing would not be stripped out.so now,,give me the code,,how to make that

We don't just give out the code if we can help it. We give hints, we try to help. We don't do the whole thing for you and post the finished product. And have you ever heard of the word "please"?

VernonDozier
Posting Expert
5,527 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 711
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You