3
3

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)

Posted at

Rubyで文字列連結のプログラムをいくつか実装しました

問題

3 つの文字列が改行区切りで与えられます。
これらの文字列をバーティカルライン | 区切りで出力してください。

①「<<」で連結する方法

    ans = ""
    for i in 1..3 do
        input_line = gets.chomp
        if i < 3 
            ans = ans << input_line << "|"
        elsif i ==3
            ans = ans << input_line
        end
    end    
    puts ans

②「+」で連結する方法

  ans = ""
    for i in 1..3 do
        input_line = gets.chomp
        if i < 3 
            ans = ans + input_line + "|"
        elsif i ==3
            ans = ans + input_line
        end
    end    
    puts ans  

以上2つの方法を取り上げました

3
3
2

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
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?