[Java] Modular Arithmetic 모듈러 연산, 나머지 연산자 공부하기 !


Math: % ( modulo )


The modulo operator - represented in Java by the % symbol - returns the remainder of dividing two numbers.

For example, 15 % 6 will return the value of 3, because that is the remainder left over after dividing 15 by 6.


자바에서 '나머지 구하기 연산자 ( 모듈러 )'는 "%"로 나타냅니다. 두수의 나머지를 계산할 때 사용되는 연산자입니다.
예를 들어, 15 % 7 = 1 입니다. 2 * 7 = 14 + 1 = 15 이기 때문이지요.
또 다른 예를 들어보겠습니다. 51 % 17 = ??? 한번 생각해보세요. 연산결과로 0을 예상하셨다면 정답입니다.

EX]
public class Modular_Arithmetic{
public static void main(String[] args){
int a = 3;
if (!( 15 % a )){
System.out.println("3의 배수입니다!, Multiple of three !");
}
}
}

아주 간단한 예시를 들어봤는데요. 지금은 모르셔도 되는 conditional statement 조건제어문 If 입니다.
다음부터 계속해서 배워보도록 하겠습니다.


+ Recent posts