Consider the following while loop. Assume that the int variable k has been properly declared and initialized. while (k < 0) { System.out.print("*"); k++; } code example

Example 1: Given an int variable n that has already been declared and initialized to a positive value, use a do...while loop to print a single line consisting of n asterisks. Use no variables other than n.

do
{
System.out.print("*");
n--;
}
while (n > 0);

Example 2: Given an int variable k that has already been declared, use a do...while loop to print a single line consisting of 53 asterisks. Use no variables other than k.

k = 0;
do{
   System.out.print("*");
   k++;
}while (k < 53);

Tags:

Java Example