Exercise
Multiples
Objetive
Write a Visual Basic (VB.Net) 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
' Import the System namespace to use Console class
Imports System
Public Class Program
' Main subroutine, entry point of the program
Public Shared Sub Main()
' Loop through numbers from 1 to 500
For i As Integer = 1 To 500
' Check if the number is divisible by both 3 and 5 using the modulo operator
If i Mod 3 = 0 AndAlso i Mod 5 = 0 Then
' If divisible by both, display the number
Console.WriteLine(i)
End If
Next
End Sub
End Class