Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 创建三角形_Ruby - Fatal编程技术网

Ruby 创建三角形

Ruby 创建三角形,ruby,Ruby,这个问题被提问者删除了。第一个问题 size = 5 size.times do |n| puts (1..(size-n)).to_a.join('') end 第二个 size = 5 size.times do |n| puts (1..(n+1)).to_a.join('') end 第一个 size = 5 size.times do |n| puts (1..(size-n)).to_a.join('') end 第二个 size = 5 size.times do

这个问题被提问者删除了。

第一个问题

size = 5
size.times do |n|
  puts (1..(size-n)).to_a.join('')
end
第二个

size = 5
size.times do |n|
  puts (1..(n+1)).to_a.join('')
end
第一个

size = 5
size.times do |n|
  puts (1..(size-n)).to_a.join('')
end
第二个

size = 5
size.times do |n|
  puts (1..(n+1)).to_a.join('')
end
如果必须根据示例使用
while
循环,请尝试:

print "Enter a starting number: "
size = gets.to_i
line = 1

while line <= size
    count = 1
    while count <= line
        print count
        count += 1
    end
    puts
    line += 1
end
如果必须根据示例使用
while
循环,请尝试:

print "Enter a starting number: "
size = gets.to_i
line = 1

while line <= size
    count = 1
    while count <= line
        print count
        count += 1
    end
    puts
    line += 1
end

要遵循与教师代码类似的格式,请执行以下操作

print "Enter a starting number: "
size = gets.to_i
line = size - 1
while line >= 0
    count = 1
    while count <= size - line
        print count
        count += 1
    end
    puts
    line -= 1
end
print“输入起始编号:”
size=get.to_i
直线=尺寸-1
当第行>=0时
计数=1

当count遵循与教师代码类似的格式时,以下方法有效

print "Enter a starting number: "
size = gets.to_i
line = size - 1
while line >= 0
    count = 1
    while count <= size - line
        print count
        count += 1
    end
    puts
    line -= 1
end
print“输入起始编号:”
size=get.to_i
直线=尺寸-1
当第行>=0时
计数=1

计数时,如果您发现答案特别有用,请确保通过单击相关灰色勾号选择并接受答案,使其变为绿色。如果您发现答案特别有用,请确保通过单击相关灰色勾号选择并接受答案,使其变为绿色。