Multiples Learn programming Java

Lesson:

Flow Control


Exercise:

Multiples


Objetive:

Create a java program to display on the screen the numbers from 1 to 500 that are multiples of both 3 and 5. (Hint: Use the modulo operator to check for divisibility by both 3 and 5.)


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++;
		}
	}
}

Juan A. Ripoll - Systems Tutorials and Programming Courses ©  All rights reserved.  Legal Conditions.