THis is program in java for First 100 Prime Number as "count<100" .

public class PrimeNumber
{


public static void main(String args[])
{
int num=4;
int count=0;
System.out.println("First 100 Prime Number is: ");
System.out.println("1");
System.out.println("2");
System.out.println("3");
while(count<100)
{
num++;
if(num%2!=0)
{
int dv=3;
while((num%dv!=0)&&(dv<=((num-1)/2)))
{
dv++;
}
if(num%dv!=0)
{
count++;
System.out.println(num);
}
}
}


}
}

And ?

actually, it prints the first 102 prime numbers (if it works at all)...

public class Algarv {
    public static void main(String args[]) {
    int numbrid = 0; // Proovime kohe algusest
    int loendur = 0; // Loendame üles, et pärast lihtsam oleks
    while(loendur < 100) // Eelkontrolliga, t2idame kuni see on 100
        {
            numbrid++;
            if(numbrid % 2 != 0)
                {
                    int abi = 3;
                    while((numbrid % abi != 0)&&(abi <= ((numbrid - 1) / 2)))
                        {
                            abi++;
                        }
                            if(numbrid % abi != 0)
                                {
                                    loendur++;
                                    System.out.print(numbrid+" ");
									System.out.println(loendur);
                                }
                }
        }
}
}

1 is not technically a prime number either so it is not true to print it out as prime with two and three.

public class Algarv {
    public static void main(String args[]) {
    int numbrid = 0; // Proovime kohe algusest
    int loendur = 0; // Loendame üles, et pärast lihtsam oleks
    while(loendur < 100) // Eelkontrolliga, t2idame kuni see on 100
        {
            numbrid++;
            if(numbrid % 2 != 0)
                {
                    int abi = 3;
                    while((numbrid % abi != 0)&&(abi <= ((numbrid - 1) / 2)))
                        {
                            abi++;
                        }
                            if(numbrid % abi != 0)
                                {
                                    loendur++;
                                    System.out.print(numbrid+" ");
									System.out.println(loendur);
                                }
                }
        }
}
}

For future reference, please have your comments in the code in English

//simple java program for finding prime nos of any range//
import java.io.*;

class PrimeNumber {
  public static void main(String[] args) throws Exception{
    int i,j;
    BufferedReader bf = new BufferedReader(
              new InputStreamReader(System.in));
    System.out.println("Enter range:");
    int num =Integer.parseInt(bf.readLine());
     int num1=Integer.parseInt(bf.readLine());
//int num=100;int num1=200;
 
    System.out.println("Prime number: ");
for(i=1;i<num||i<num1;i++)
{	
	for (j=num; j<i; j++){
        int n = i%j;
        if (n==0){
          break;
        }
      }
      if(i == j){
        System.out.print("  "+i);
      }
    }
  }
}
java syntax(Toggle plain text)
import java.io.*;

class PrimeNumber {
  public static void main(String[] args) throws Exception{
    int i,j,count =0;
    BufferedReader bf = new BufferedReader(
              new InputStreamReader(System.in));
    System.out.println("Enter range:");
    int num =Integer.parseInt(bf.readLine());
     int num1=Integer.parseInt(bf.readLine());

    System.out.println("Prime number: ");

for(i=num;i<num1;i++)
{	
	 for (j=2; j<i; j++)
	{
        int n = i%2;
        if (n==0)
		{
	
         	 break;	
	        }
      	}
      	if(i == j)
	{
        System.out.print("  "+i);
      	}
    	}


  	}
}

import java.io.*;
class Primenumber{
public static void main(String args[])throws IOException{
InputStreamReader input= new InputStreamReader(System.in);
BufferedReader reader= new BufferedReader(input);

System.out.println("enter your first num");
int num1=Integer.parseInt(reader.readLine());
System.out.println("enter your second num");
int num2=Integer.parseInt(reader.readLine());
int count=0;//count has to outside of "for"

for(int x=num1;x<num2;x++){
for(count=2;count<x;count++){

if(x%count==0){
break;
}

}
if(x==count){
System.out.print(x+",");

}
}

}
}
//9 isn't a prime number I fixed it so that it works properly

:sigh: Closing this zombie now.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.