ex>
class opPlus{
public static void main(String[] args){
int x=1;
System.out.println("x: "+x);
// 이렇게 하면 x가 추가로 찍혀서 나옴
for(int i=1;i<=3;i++)
System.out.print("x: "+x++ +" ");
// x++ : x 증가
}
}
Mathmatics methods Math.pow(x, y) : return x^y Math.sqrt(x) : square root of x Math.min Math.max Math.PI Math.E Math.random() : (0 to 1) 에서 랜덤한 값을 반환
그런데 왜 Math는 클래스인데 객체를 안만들고 사용할까?
static methods일 경우 Calling format : class_name.method_name 형식으로 static methods를 불러야 하며 instance method와 다르게 instance 없이도 호출 가능
double
이면, 다른쪽 피연산자는 double
한쪽 피연산자가 float
이면, 다른쪽 피연산자는 float
한쪽 피연산자가 long
이면, 다른쪽 피연산자는 long
그거 아니면 두 피연산자는 int
임double x = 3.75;
int n = (int) x;
ex>
byte b = (byte) 100000;
short s = (short) 100000;
System.out.println("b : " + b);
System.out.println("s : " + s);
short s = 100 + 1
위와 같은 코드를 예로 들어 보면 자바는 기본 자료형이 int이기 때문에 int to short 형태를 띄고 있음. 따라서 위의 코드는 에러가 남