Answer:
The solution code is written in Java.
- public class Main {
- public static void main(String[] args) {
- int n = 5;
- int j;
- do{
- System.out.print("*");
- n--;
- }while(n > 0);
- }
- }
Step-by-step explanation:
Firstly, declare the variable n and assign it with value 5 (Line 4). Next declare another variable j.
Next, we create a do while loop to print the n-number of asterisks in one line using print method. In each iteration one "*" will be printed and proceed to the next iteration to print another "*" till the end of the loop. This is important to decrement the n by one before the end of a loop (Line 9) to ensure the loop will only run for n times.