Question about adding three asterisks to every other print line (loops)

Hi everyone, been a lurker for awhile and I have a question that I'd appreciate help with.

I'm working on a program which asks to display three asterisks at the end of every 3rd line of output. So far I have the following , but I'm just confused about how to go about this.

Code:

`import java.util.Scanner;`

public class LabAssign7

{

public static void main(String args[])

{

// Envokes scanner

Scanner scan = new Scanner( System.in );

// Asks user for integer greater than zero

int n = 0;

while (n <= 0) {

System.out.print( "Enter an integer greater than zero -> " );

n = scan.nextInt();

}

System.out.print( "\n" );

//Declares loop variable

int i;

// Calculates text to display set number of times

for ( i = 0; i < n ; i++)

{

System.out.print( "I like to sit by the fireplace.\n" );

}

System.out.print( "\nThe program has ended.\n" );

}

}

Output:

Code:

` Enter an integer greater than zero -> -9`

Enter an integer greater than zero -> 9

I like to sit by the fireplace.

I like to sit by the fireplace.

I like to sit by the fireplace.

I like to sit by the fireplace.

I like to sit by the fireplace.

I like to sit by the fireplace.

I like to sit by the fireplace.

I like to sit by the fireplace.

I like to sit by the fireplace.

The program has ended.

Any hints / comments would be appreciated. Thanks!

Re: Question about adding three asterisks to every other print line (loops)

The modulus operator (%) is useful to detecting every nth value in a sequence of numbers.

0%4 is 0

1%4 is 1

2%4 is 2

3%4 is 3

4%4 is 0

5%4 is 1

6%4 is 2

7%4 is 3

8%4 is 0

9%4 is 1

Re: Question about adding three asterisks to every other print line (loops)