0
make coding a program to display the output as below:
output high hill : 4 the amouny of the hill : 2 * ** *** **** *** ** * * ** *** **** *** ** *
2 Answers
+ 5
Can be done with one loop, let MAX_ITTERATIONS = 'amount of the hill', let MAX_LENGTH = 'high hill'.
final int MAX_ITTERATIONS = 2,
MAX_LENGTH = 4;
int curItteration = 1,
curLength = 1,
curMaxLength = 1;
boolean moreStars = true;
do{
if(moreStars && curLength > curMaxLength)
{ // stars increasing
System.out.println();
curMaxLength++;
curLength = 1;
}
else if
(!moreStars && curLength > curMaxLength)
{ // stars decreasing
System.out.println();
curMaxLength--;
curLength = 1;
}
if(curMaxLength < 1)
{ // reset to new hill
moreStars = true;
curItteration++;
curMaxLength = 1;
curLength = 1;
continue;
}
System.out.print("*");
curLength++;
if(curLength > MAX_LENGTH) // time to decrease
moreStars = !moreStars;
}while(curItteration <= MAX_ITTERATIONS);