Eval two

mail@pastecode.io avatar
unknown
java
7 months ago
923 B
12
Indexable
Never
import java.util.Scanner;

public class EvalTwo {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        
        while (true) {
            System.out.print("Enter an even positive integer: ");
            int number = scanner.nextInt();
            
            if (number % 2 != 0) {
                System.out.println("You entered an odd number");
                break;
            }
            
            int count = 0;
            for (int i = 1; i <= Math.sqrt(number); i++) {
                if (number % i == 0) {
                    if (number / i == i) {
                        count++;
                    } else {
                        count += 2;
                    }
                }
            }
            
            System.out.println(number + " has " + count + " divisors");
        }
        
        
    }
}
Leave a Comment