Perl:标量数据-练习4
时间:2010-04-06 来源:xuezhilei40308
练习4:写一个程序,用户能输入两个字,不在同一行,输出为两个数的积。
sourcecode:
#!/usr/bin/perl -w
print "please input the first number:\n";
chomp ($i=<STDIN>);
print "please input the second number:\n";
chomp ($j=<STDIN>);
$product=$i*$j;
print "The product of $i multiplied by $j is $product";
note:
1. 变量名的选择,要易读易懂,答案中给出的变量名是$one, $two.
2. 一般来说,从键盘读入的值中,都会用chomp函数去掉结尾处的换行符再赋值给变量。否则,在最后一条Print语句中,输出会显示成三行,分别在$i $j处另起一行。
3. 最后一句修改成:the product of multiplying $i by $j is $product.
sourcecode:
#!/usr/bin/perl -w
print "please input the first number:\n";
chomp ($i=<STDIN>);
print "please input the second number:\n";
chomp ($j=<STDIN>);
$product=$i*$j;
print "The product of $i multiplied by $j is $product";
note:
1. 变量名的选择,要易读易懂,答案中给出的变量名是$one, $two.
2. 一般来说,从键盘读入的值中,都会用chomp函数去掉结尾处的换行符再赋值给变量。否则,在最后一条Print语句中,输出会显示成三行,分别在$i $j处另起一行。
3. 最后一句修改成:the product of multiplying $i by $j is $product.
相关阅读 更多 +
排行榜 更多 +