반응형

자바절댓값

    [Java] JAVA 절댓값 구하는 함수 Math.abs()

    [Java] JAVA 절댓값 구하는 함수 Math.abs()

    Java에서 자체 라이브러리인 Math의 abs() 함수를 사용하면 편하게 절댓값을 구할 수 있습니다. public static void main(String[] args){ int a = 100; int b = -100; System.out.println("a의 절댓값 : " + Math.abs(a)); System.out.println("b의 절댓값 : " + Math.abs(b)); if(Math.abs(a) == Math.abs(b)){ System.out.println("a와 b의 절댓값은 같습니다!"); } } /* a의 절댓값 : 100 b의 절댓값 : 100 a와 b의 절댓값은 같습니다! */ Math.abs()는 4가지의 숫자 타입(int, long, float, double)에 모두 사..

반응형