为什么乘法不适用于 Read-Host 值 [英] Why does multiplication does not work with Read-Host value
本文介绍了为什么乘法不适用于 Read-Host 值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
$table_num = Read-Host -Prompt 'Enter the table number you want to get printed'
for ($i=1; $i-lt 11; $i++){
$ans = ($table_num*$i)
write "$table_num*$i=$ans"
}
以上是我尝试执行的脚本,结果如下:
Above is the script which I was trying to execute and I get the result as below:
Enter the table number you want to get printed: 5
5*1=5
5*2=55
5*3=555
5*4=5555
5*5=55555
5*6=555555
5*7=5555555
5*8=55555555
5*9=555555555
5*10=5555555555
我不熟悉脚本编写并帮助我编写代码.
I am new to scripting and help me with my code.
推荐答案
感谢您的解答!!
实际上我已经添加了数据类型int
.脚本如下所示.
Actually I have added the data type int
. And the script is good as below.
$table_num = Read-Host -Prompt 'Enter the table number you want to get printed'
For ($i=1; $i-lt 11; $i++){
$ans = ([int]$table_num*$i)
write "$table_num * $i = $ans"
}
这篇关于为什么乘法不适用于 Read-Host 值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文