Finding Odd and Even Number using PowerShell

During my PowerShell session, someone asked how easy is it to use PowerShell for mathematical calculations?

It depends what we do. For example, if you need to get the rounded value of 9.2:

You can explore [Math] for your needs.

Any logic without using built-in classes in PowerShell, say how to find Odd and Even Numbers using PowerShell, is very simple and easy to achieve.

Demo using precedence Operator , For Each and If on one line.

 1..20 | % {if($_ % 2 -eq 0 ) {"$_ is even"} }

 1..20 | % {if($_ % 2 -eq 1 ) {"$_ is odd"} }

Other Languages
This article is also available in the following languages: