2
3

データ型の変換(Java、Python)

Last updated at Posted at 2024-01-24

データ型の変換についてまとめました。
今回は整数型から文字列に変換する場合を比較します。

Java

public class Main1 {
  public static void main(String[] args) {
      // 自分の得意な言語で
      // Let's チャレンジ!!

      //String line = sc.nextLine();
      int A = 437326;
      int B = 9085;
      int ansA = A / B;
      int ansB = A % B;
      //  ラッパークラスを用いて数値を文字列に変換して出力する
      System.out.println(Integer.valueOf(ansA).toString() + " " + Integer.valueOf(ansB).toString());
  }
}

Python

A = 437326
B = 9085
ansA = int(A/B)
ansB = A % B
print(str(ansA) + " " + str(ansB))

Pythonの方が楽ですね。

2
3
3

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