1public class Main {
2 public static void main(String[] args) {
3 for (int i = 2; i < 100; ++i) {
4 boolean isPrime = true;
5 int sqrt = (int)Math.ceil(Math.sqrt(i));
6 for (int divisor = 2; divisor <= sqrt; ++divisor) {
7 if (i % divisor == 0) {
8 isPrime = false;
9 break;
10 }
11 }
12 if (isPrime) {
13 System.out.println(i);
14 }
15 }
16 }
17}
1class PrimeNumbers
2{
3 public static void main (String[] args)
4 {
5 int i =0;
6 int num =0;
7 //Empty String
8 String primeNumbers = "";
9
10 for (i = 1; i <= 100; i++)
11 {
12 int counter=0;
13 for(num =i; num>=1; num--)
14 {
15 if(i%num==0)
16 {
17 counter = counter + 1;
18 }
19 }
20 if (counter ==2)
21 {
22 //Appended the Prime number to the String
23 primeNumbers = primeNumbers + i + " ";
24 }
25 }
26 System.out.println("Prime numbers from 1 to 100 are :");
27 System.out.println(primeNumbers);
28 }
29}
1public class PrimeNumbersFrom1To100
2{
3 public static void main(String[] args)
4 {
5 int maxNumber = 100;
6 boolean prime = true;
7 String primeNumbers = "";
8 for(int a = 1; a <= maxNumber; a++)
9 {
10 prime = checkPrime(a);
11 if(prime)
12 {
13 primeNumbers = primeNumbers + a + " ";
14 }
15 }
16 System.out.println("Display prime numbers from 1 to " + maxNumber + ": ");
17 System.out.println(primeNumbers);
18 }
19 public static boolean checkPrime(int number)
20 {
21 int remainder;
22 for(int a = 2; a <= number / 2; a++)
23 {
24 remainder = number % a;
25 // if remainder is equal to 0 then number is not prime
26 if(remainder == 0)
27 {
28 return false;
29 }
30 }
31 return true;
32 }
33}