Advertisements
Instead of using break statement in finding the prime nos ,is there any other way ?? if it is there pls tell that also
import java.io.*; class FindPrimeWithoutBreak { public static void main(String[] args) { for (int number = 2; number <= 100; number++) { int maxFactor = (int)Math.sqrt(number); boolean isPrime = true; int factor = 2; while (isPrime && factor <= maxFactor) { if (number % factor == 0) { isPrime = false; } factor++; } if (isPrime) System.out.println(number); } } }