Multiples Learn programming Java

Lesson:

Flow Control


Exercise:

Multiples 31


Objetive:

Create a java program to write on screen the numbers from 1 to 500 that are multiples of 3 and also multiples of 5 (hint: use the remainder of the division).


Code:

public class Main
{
	public static void main(String[] args)
	{
		int i = 1;
		while (i <= 500)
		{
			if ((i % 3 == 0) && (i % 5 == 0))
			{
				System.out.printf("%1$s ", i);
			}
			i++;
		}
	}
}