2
2

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入門 変数の比較(Math.max)

Posted at

Java
変数の比較

変数aと変数b、どちらが大きいか判断するためにJavaにはMath関数が用意されています。

sample.java
public class Sample {
	public static void main (String[] arg) {
		// 変数aとbに0~89の乱数を代入
		int a = new java.util.Random().nextInt(90);
		int b = new java.util.Random().nextInt(90);
		// 変数maxに値が大きい方を代入
		int max = Math.max(a, b);

		System.out.println (max);
	}

}

C言語では変数を比較する式をif文を使って書く必要がありますが、Javaではそれが不要です。
便利ですね。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?