Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want my out put like this.
Input number = 5
----*
---***
--*****
-*******
*********


But my output is...
----*
---**
--***
-****
*****

please help me. how to write short code.
Thank..

Update! My code does work like this.
C#
import java.util.*;
public class test {


public static void main(String[] args) {
Scanner k = new Scanner(System.in);
System.out.print("Input row : ");
int n = k.nextInt();
for (int i = 1; i <= n; i++) { 
for (int j = n; j > i; j--) { 
System.out.print(" ");
}
for (int j = i; j > 1; j--) {
System.out.print("*");
}

//
for (int j = 1; j <= i; j++) { // my teacher don't want this line.
System.out.print("*");  // my teacher don't want this line.
}
// But teacher want my output like.
----*
---***
--*****
-*******
*********
//

System.out.println();

}
}
}
Posted
Updated 17-Jan-14 5:23am
v5
Comments
Ron Beyer 17-Jan-14 11:10am    
Please show your code, we won't just do it for you, but we can help you where you are stuck.
terzasek 17-Jan-14 11:24am    
sure... ^ ^

1 solution

This isn't a major change from the code you have at the moment - or it shouldn't be.
At the moment you are probably running a loop for each line (i.e. a for loop, 1 to the input number) and outputting (inputNumber - loopCounter) undelines, then loopCounter stars.

So instead, create a new variable: starsCount and start it at 1. Then inside your loop output the same number of underlines, but output starsCount stars, and increase it by two each time.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900