19
20

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 5 years have passed since last update.

Javaの数値リテラルの表記規則まとめ

Posted at

整数型リテラル

  • 小数点がないリテラルは、デフォルトで int。
  • 末尾に "L" または "l" で long 型リテラルとなる。

浮動小数点数型リテラル

  • 小数点があるリテラルは、デフォルトで double。
  • 末尾に "F" または "f" で float 型リテラルとなる。
  • 末尾に "D" または "d" で double 型リテラルと宣言できる。

X進表記

  • 整数型リテラルのみX進表記可能。
  • 浮動小数点数型リテラルはX進表記不可能。
  • float や double に代入するリテラルであっても、小数点がつかず、末尾に何もつかなければ int とみなされるため、X進表記可能。

先頭に付加する文字

進数 文字
2進 (Java 7以降) "0b" または "0B"
8進 "0"
16進 "0x" または "0X"

アンダースコア (Java 7以降)

以下のポイント「以外」にアンダースコアを入れて表記できる。

整数型の場合

  • 先頭
  • 0b, 0B, 0x, 0X の直後(8進の 0 の直後はあってもよい)
  • L, l の直前
  • 末尾

浮動小数点型の場合

  • 先頭
  • 小数点の隣(前後)
  • D, d, F, f の直前
  • 末尾
19
20
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
19
20

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?