Hunter McMillen wrote:dont think of it as trying to print a triangle, think of it as trying to print out a rectangle partially filled with spaces.
Now look at the number of spaces (marked by '-' ) versus the number of stars on each line. There is a pattern.
Hunter
EDIT: fixed typo
but i need to implement this only with the help of " for " loop , no other loops or control structures.
then how to do this , the above programe is typing the stars from right to left
but in this we need to put a 4 empty space in 0 line and then we have to reduce the space , how to achieve this with for loops.
naved momin wrote:but i need to implement this only with the help of " for " loop , no other loops or control structures.
then how to do this , the above programe is typing the stars from right to left
but in this we need to put a 4 empty space in 0 line and then we have to reduce the space , how to achieve this with for loops.
You know how to print stars "*", you should also know how to print spaces " ".
You know how to increase number of stars, you should also know how decrease number of spaces.
Follow fred rosenberger advice on "fill in the blanks" before code.
Coding is simply turning algorithm into program, you have to find out the algorithm first.
naved momin wrote:
i have made it ,. tricky , but still succeded just with the help of for loop
Try to remove all the for statements and leave only the print and println statements.
There is a way to make use of for loop to print space x times and print star y times where x + y = 4.
naved momin wrote:
i have made it ,. tricky , but still succeded just with the help of for loop
Try to remove all the for statements and leave only the print and println statements.
There is a way to make use of for loop to print space x times and print star y times where x + y = 4.
i didnt get you actually
as you had said , i have tried , will you throw some solution to this .
naved momin wrote:i didnt get you actually
as you had said , i have tried , will you throw some solution to this .
it is just printing a star one below the other.
I meant the multiple for loops with label break didn't really make use of the power of for loops.
i.e. You have for loop statement in your code but they all iterate once.
Try to turn the following pseudocode into java code
step 1. iterate (x) from 1 to 4
step 2. print (4-x) spaces
step 3. print (x) stars
step 4. print "line break and/or carriage return"