Public Class Tester
Public Shared Sub Main
Console.WriteLine(Power(12))
Console.WriteLine(Power(2,2))
End Sub
' use iteration to calculate power
Shared Function Power(ByVal base As Integer, _
Optional ByVal exponent As Integer = 2) As Integer
Dim total As Integer = 1
Dim i As Integer
For i = 1 To exponent
total *= base
Next
Return total
End Function ' Power
End Class
144
4