Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
4
Help us understand the problem. What is going on with this article?
@ydzum1123

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

More than 1 year has passed since last update.

文字列(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

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

4
Help us understand the problem. What is going on with this article?
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
ydzum1123
システム、サービスを作れる人になりたい。HTML5+CSS3,JavaScript,Python3,Ruby,Java,COBOL,OracleDB(SQL)。AdobeCCも少し。ほかにもPHP,Julia,Go,flutter(dart),GCP(Firebase),AWS,ブロックチェーン,ディープラーニングを勉強中。

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
4
Help us understand the problem. What is going on with this article?