0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Ruby】入力された数字に応じてピラミッド状に文字を返す

Last updated at Posted at 2020-10-20

イメージはこんなかんじ。

スクリーンショット 2020-10-20 14.19.16.png

while str = STDIN.gets
  break if str.chomp == "exit"#文字列の末尾から改行コードを取り除いた文字列を返します
  n=str.to_i#文字列を整数に返すメソッド
  puts n
  for x in 0..n-1
    (n-x-1).times{printf(" ")}
    for y in 1..2*x+1
      printf("*")
    end
    puts "\n"
  end
end

Rubyのお役立ち情報

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?