Help us understand the problem. What is going on with this article?

【プログラミング学習】 言語別ロジック比較 part.2(変数:数値、文字列)

文字列(String)、数値(Int)の宣言と、それを同時に出力する処理の確認まで。

2.変数

Ruby

sample.rb
# コメント行は"#"で記述
moji = "ABC" #文字列
suji = 123 #数値

# この書き方はNG
# puts moji + suji

# この書き方はOK
puts moji + suji.to_s
$ ruby sample.rb
ABC123

Python3

sample.py
moji = "ABC"
suji = 123

# この書き方はNG
# print(moji + suji)

# この書き方はOK
print(moji + str(suji))
$ python test.py
ABC123

Swift

sample.swift
import Foundation
var moji = "ABC"
var suji = 123

// この書き方はNG
//print(moji + suji)

// この書き方はOK
print(moji + String(suji))
(playground)
ABC123

Java

sample.java
package sample;

public class Main {
    public static void main(String[] args) {
        String moji = "ABC";
        int suji = 123;

        // Javaはこの書き方でOK
        System.out.println(moji + suji);
    }
}
(eclipse console)
ABC123

C#

sample.cs
using System;
public class HelloWorld {
    static public void Main () {
        String moji = "ABC";
        int suji = 123;

        // C#もこの書き方でOK
        Console.WriteLine(moji + suji);
    }
}

(手元の実行環境では'mono'を使って実行)

$ mcs sample.cs
(コンパイル成功)
$ mono sample.exe
ABC123

学習してる内容はもっと先行ってるので、どんどんアウトプットしたい。

ydzum1123
システム、サービスを作れる人になりたい。HTML5+CSS3,JavaScript,Python3,Ruby,Java,COBOL,OracleDB(SQL)。AdobeCCも少し。ほかにもPHP,Julia,Go,flutter(dart),GCP(Firebase),AWS,ブロックチェーン,ディープラーニングを勉強中。
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした