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クラスまとめ

Posted at

package sample1;

public class MathAllSample {
public static void main(String[] args){

	int a = 100, b = 99, c;//大小判定(大)の場合
	
	c = Math.max(a, b);
	System.out.println(a +"と"+ b +"では"+ c +"の方が大きい");
	
	double d = 14.5,e = 4.56, f;//大小判定(小の場合)
	
	f = Math.min(d, e);
	
	System.out.println(d +"と"+ e +"では"+ f +"の方が大きい");
	
	double g = 3.14, h;//小数点以下を切り上げ
	h = Math.ceil(g);
	 
	System.out.println(g +"の小数点以下を切り上げると"+ h +"になります");
	 
	double i = 3.14, j;//小数点以下切り捨て
	j = Math.floor(i);
	
	System.out.println(i +"の小数点以下を切り捨てると"+ j +"になります");
	
	double k = 3.14, l = 49.6, m,n;//四捨五入
	m = Math.round(k);
	n = Math.round(l);
	
	System.out.println(k +"を四捨五入すると"+ m +"になります");
	System.out.println(l +"を四捨五入すると"+ n +"になります");
	
	double o = 2, p = 2, q;//累乗
	q = Math.pow(o, p);
	
	System.out.println(o +"を"+ p +"乗した値は"+ q +"です");
	
	
	double r = 2,s, t = 2, u;
	s = Math.sqrt(r);//平方根
	u = Math.cbrt(t);//立方根
	
	System.out.println(r +"の平方根は"+ s +"です");
	System.out.println(t +"の平方根は"+ u +"です");
	
	double v = Math.random();
	
	System.out.println(v);//0~1.0未満の乱数
	
	double w = Math.random()*7;//0~7までの乱数
	System.out.println(w);
	
}

}

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?