(这些文章都是从我的个人主页上粘贴过来的,大家也可以访问我的主页 www.iwangzheng.com)
回到家里,用的还是windows系统,ruby的编辑器换成了Aptana Studio 3
puts "Please input the first Number:"
number1=gets
puts "Please input a
operator(+,-,*,/):"
op=gets
puts "pleasse input the second
Number:"
number2=gets
case op.chomp
when "+"
result=number1.to_i + number2.to_i
when
"-"
result=number1.to_i - number2.to_i
when "*"
result=number1.to_i *
number2.to_i
when "/"
result=number1.to_i / number2.to_i
end
puts
"Result:#{number1.chomp}#{op.chomp}#{number2.chomp}=#{result}"
运行一下:
$ ruby calculator.rb
Please input the first Number:
2
Please input a
operator(+,-,*,/):
*
pleasse input the second
Number:
8
Result:2*8=16
原文:http://www.cnblogs.com/iwangzheng/p/3577990.html