here is my code but i need to get output if my Sample input:
3
Sample output
*
***
*****
***
*
will must look like this! now can anyone please help me with this ..

public class p2.java{
     public static void main (String args[]){
     int x;
     SimpleInput sInp = new SimpleInput();
     x = sInp.getInt("please enter an Integer");
     int y = 1;
     char c='*';
     char z=' ';
     while(y<=x){
       int n=x-y;
       while(n>0){
       System.out.print(z);
       n--;
       }
     int k = 1;
     while (k<=y){
     System.out.print(c);
     k++;
     }
     System.out.println(z);
          y++;
       }
     }
   }

i did this problem using simple input . so far this code work perfect but i just cant get my desire output !

Recommended Answers

All 8 Replies

Reposted with code tags:

[code=JAVA] // code]

[/code]

or

[code]

// code]

[/code]

3
Sample output
  *
 ***
*****
 ***
  *
public class p2.java{
     public static void main (String args[]){
     int x;
     SimpleInput sInp = new SimpleInput();
     x = sInp.getInt("please enter an Integer");
     int y = 1;
     char c='*';
     char z=' ';
     while(y<=x){
       int n=x-y;
       while(n>0){
       System.out.print(z);
       n--;
       }
     int k = 1;
     while (k<=y){
     System.out.print(c);
     k++;
     }
     System.out.println(z);
          y++;
       }
     }
   }

We can't run this program. What is the actual output? Use code tags around the asterisks.

[code]

// put asterisks here

[/code]

the out put of my posted code is below :if my Sample input:
3
Sample output will be
*
**
***

the out put of my posted code is below :if my Sample input:
3
Sample output will be
*
**
***

i can see the output i post got left sided but in actual its the opposite, its a right side triangle like : *
**
***[

the out put of my posted code is below :if my Sample input:
3
Sample output will be
*
**
***

Like I said, put code tags around the asterisks.

*
  ** 
***

Is it really lopsided like that or does it look like this?

*
 **
***

So it looks like the above, but it's supposed to look like this?

*
 ***
*****
 ***
  *

yes it suppose to look like a rhombus .. but could not make that look like so..can u please what should i change or include so that it look like rhombus?

First step. Indent your code in such a way that it's very clear where the nested loops start and stop. The logic is hard to follow due to the indentation. Proper indentation will really clarify things. Right now I simply can't follow the code due to the non-constant indentation. Second, maybe throw some comments in there. Third, pencil and paper all the way. Figure out exactly what YOU do as a person to draw this rhombus, step by step, don't leave anything out. Remember, you have to explicitly tell the computer what to do. Nothing is obvious. That gets you the algorithm. Then it's a matter of turning the algorithm into code. But get the code lined up correctly and the problem may very well simply pop out at you.

*
***
*****
***
*
display the output as above using c++ or c

commented: Wow, you can't even hijack a thread in the correct forum to cheat on your homework. Bravo. -2
commented: This is java forum -1

*
***
*****
***
*
display the output as above using c++ or c

This is a java forum. Start a new thread in the C forum but don't expect people to give you the answer if don't show some effort and post what you have done so far.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.