0
0

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

Javaのtrueとfalse

Last updated at Posted at 2020-05-23

###trueとfalse
真偽値のデータ型はbooleanです。

Main.java
class Main {
  public static void main(String[] args) {
    int number = 5;
  }
  if (isEven(number)) {
    System.out.println(number + "偶数");
  } else {
    System.out.println(number + "奇数");
  public static boolean isEven(int a) {
    return a % 2 == 0;
  }
}

上記はisEvenメソッドは引数の値が偶数かどうかを調べ、偶数であればtrue、奇数であればfalseを返します。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?