LoginSignup
17
13

More than 5 years have passed since last update.

符号の反転

Last updated at Posted at 2014-09-10
int i = 5;
System.out.println((-1)*i)//-5

今まで符号の判定をする際には-1をかける形で書いていた記憶があったのですが
マイナス一つで符号が反転できることを言語仕様を読んでいて見つける。

The Java Language Specification, Java SE 8 Edition

int i = 5;
System.out.println(-i);//-5

int a=6,b=-5;
System.out.println(a*-b);//30
System.out.println(a/-b);//1
17
13
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
17
13