0

make coding a program to display the output as below:

output high hill : 4 the amouny of the hill : 2 * ** *** **** *** ** * * ** *** **** *** ** *

15th Apr 2017, 3:48 PM
Ike Antika
Ike Antika - avatar
2 Respuestas
15th Apr 2017, 4:24 PM
Sachin Artani
Sachin Artani - avatar
+ 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);
15th Apr 2017, 5:58 PM
Rrestoring faith
Rrestoring faith - avatar