Starting from:
$30

$24

Assignment 2 Solution

Create a class Welcome1.




Create an application that asks the user his/her age, then in a loop it divides the user age over 2 and prints the result until the result of division is one (The result of division must be an integer). The application runs to another loop and this time it counts from 0 to the age of the user and in each iteration it prints out the number of stars equal to the counter. After it finished the application asks the user if he/she want to continue or not, if not it prints a goodbye message and exits, otherwise it asks a new age and it continues.




You must have a:




do-while loop with a guard variable




while loop with a guard variable




for loop




if-else statement







You need to think carefully and find out where the application of each loop is more appropriated. break and continue statements are not allowed.




Example:




Please enter your age: 5




The result is:




5,2,1




*




**




***




****




*****




Do you want to continue? (Y/N) y




Please enter your age: 2




The result is:




2, 1




*




**




Do you want to continue? (Y/N) N




Goodbye!












More products