제수의 개수가 짝수인지 홀수인지 확인하기 위해 Java 코드는 다음과 같습니다. -
예
import java.io.*;
import java.math.*;
public class Demo{
static void divisor_count(int n_val){
int root_val = (int)(Math.sqrt(n_val));
if (root_val * root_val == n_val){
System.out.println("The number of divisors is an odd number");
}else{
System.out.println("The number of divisors is an even number");
}
}
public static void main(String args[]) throws IOException{
divisor_count(25);
}
} 출력
The number of divisors is an odd number
Demo라는 클래스에는 특정 숫자의 제수가 짝수인지 홀수인지 확인하는 'divisor_count'라는 함수가 포함되어 있습니다. 메인 함수에서 'divisor_count'는 정의된 값으로 호출됩니다. 콘솔에 관련 메시지가 표시됩니다.