小编N.S*_*ess的帖子

在PowerShell中查找中间数

我在PowerShell中练习并且正在进行用户响应输入,其中一个选项是输入3个数字,程序将返回中间数字.我这样做了一百万次,似乎我无法让它始终如一地返回中间数字.

例如,当我的数字是1,23452342和3时,它表示3是中间数字.

这是我的代码:

if ($response -eq 1) {
    $a = Read-Host "Enter a number "
    $b = Read-Host "Enter a second number "
    $c = Read-Host "Enter a third number "

    if (($a -gt $b -and $a -lt $c) -or ($a -lt $b -and $a -gt $c)) {
        Write-Host "$a is the middle number"
    }
    if (($b -gt $a -and $b -lt $c) -or ($b -gt $c -and $b -lt $a)) {
        Write-Host "$b is the middle number"
    }
    if …
Run Code Online (Sandbox Code Playgroud)

powershell logic conditional if-statement numbers

0
推荐指数
1
解决办法
108
查看次数

标签 统计

conditional ×1

if-statement ×1

logic ×1

numbers ×1

powershell ×1