Java examples for Data Structure:Algorithm
How to generate prime numbers between 1 and given number using for loop
public class Main { public static void main(String[] args) { int limit = 100; System.out.println("Prime numbers between 1 and " + limit); for (int i = 1; i < 100; i++) { boolean isPrime = true; for (int j = 2; j < i; j++) { if (i % j == 0) { isPrime = false;//from w ww . j ava2 s .co m break; } } if (isPrime){ System.out.print(i + " "); } } } }