954,541 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Re: find 100 first prime number

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);
}
}
}

}
}

jips11in
Newbie Poster
1 post since Oct 2007
Reputation Points: 10
Solved Threads: 0
 

And ?

masijade
Industrious Poster
Moderator
4,253 posts since Feb 2006
Reputation Points: 1,471
Solved Threads: 494
 

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

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 
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);
                                }
                }
        }
}
}
-ordi-
Junior Poster in Training
92 posts since Dec 2009
Reputation Points: 18
Solved Threads: 11
 

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

tjsail
Light Poster
40 posts since Nov 2009
Reputation Points: 10
Solved Threads: 3
 
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

javaAddict
Nearly a Senior Poster
Team Colleague
3,329 posts since Dec 2007
Reputation Points: 1,014
Solved Threads: 448
 
//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);
      }
    }
  }
}
shruths2890
Newbie Poster
3 posts since Mar 2010
Reputation Points: 10
Solved Threads: 0
 
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);
      	}
    	}


  	}
}
shruths2890
Newbie Poster
3 posts since Mar 2010
Reputation Points: 10
Solved Threads: 0
 

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

Brickhouse11
Newbie Poster
1 post since Feb 2011
Reputation Points: 10
Solved Threads: 0
 

:sigh: Closing this zombie now.

masijade
Industrious Poster
Moderator
4,253 posts since Feb 2006
Reputation Points: 1,471
Solved Threads: 494
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You