输入整数6
输出:11 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
尝试循环,但未能获得输出。
def pyramid(i)
(1..i).each do |n|
1.upto(n) do |x|
print "#{x} " # Mind double quotes
end
puts
end
end
pyramid(6)
阅读更多关于Ruby I/O的信息
阅读更多关于Ruby中的循环