program to print 1-100 prime number and throw exception for composite number in given range
问题 i have made a program to print 1-100 prime numbers. please help me to throw exception for composite number in range of 1-100 numbers. i am a beginner so any help will be appreciated. public static void main(String[] args) { System.out.println("Prime numbers from 1 - 100 are :"); int i = 0; int x = 0; for (i = 1; i <= 100; i++) { int ctr = 0; for (x = i; x >= 1; x--) { if (i % x == 0) { ctr = ctr + 1; } } if (ctr == 2) { System.out.println(i); } } } 回答1: I'd rather implement isPrime method and