Exercise
Multiple operations and precedences
Objetive
Write a Visual Basic (VB.Net) program to print the result of the following operations:
-1 + 3 * 5
(24 + 5) % 7
15 + (-4) * 6 / 11
2 + 10 / 6 * 1 - 7 % 2
Code
' Main class definition
Public Class Program
' Main subroutine, entry point of the program
Public Shared Sub Main()
' Perform and store the result of the operation: -1 + 3 * 5
Dim result1 As Integer = -1 + 3 * 5
' Perform and store the result of the operation: (24 + 5) % 7
Dim result2 As Integer = (24 + 5) Mod 7
' Perform and store the result of the operation: 15 + (-4) * 6 / 11
Dim result3 As Integer = 15 + (-4) * 6 \ 11
' Perform and store the result of the operation: 2 + 10 / 6 * 1 - 7 % 2
Dim result4 As Integer = 2 + 10 \ 6 * 1 - 7 Mod 2
' Display each result on the screen
Console.WriteLine("Result of -1 + 3 * 5 = " & result1)
Console.WriteLine("Result of (24 + 5) % 7 = " & result2)
Console.WriteLine("Result of 15 + (-4) * 6 / 11 = " & result3)
Console.WriteLine("Result of 2 + 10 / 6 * 1 - 7 % 2 = " & result4)
End Sub
End Class