1
1

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.

実数型で変数定義したのに整数型になる。

Last updated at Posted at 2016-02-27

変数を実数型で定義しても、式が整数型のみであれば、結果は整数型となってしまうので
注意。

12.0
12.5

Variable.java
class Variable {
	public static void main(String[] args){
		int i,j;
		double f,g;

		i=10; j=15;
		f=(i+j)/2;
		g=(i+j)/2.0;
		System.out.println(f);
		System.out.println(g);
	}
}

g=(i+j)/2.0としたり、g=(double)(i+j)/2としたりすればよい。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?