Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

write a script to generate n prime no.s?

Answer Posted / dushant

import java.io.*;
import java.util.*;

class Prime
{
static BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));
int cnt = 0,j;
Prime()
{
try
{
System.out.print("Enter A Number :");
int n = Integer.parseInt(br.readLine());


for(int i =1 ;i <= n ;i++)
{

for( j = 1 ; j <= i ;j++)
{
if(j==1) //as 1 is Common Factor For
All
{
cnt ++;
}
if(i % j == 0 && j !=i) //Condition j!=i because at
1st loop
//i=1 j=1 so i%j==0 and 1 is not prime no
{
cnt ++;
}
if(cnt == 3)
{
break;
}
if(cnt==2 && i == j )
{
System.out.println(i);
}
}
cnt=0;

}

}
catch(Exception e)
{
System.out.println(e);
}


}

public static void main(String args[])
{
new Prime();
}
}

Is This Answer Correct ?    7 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are prefix dereferencer? List them.

919


Define say() function in perl?

904


Which operator in perl is used for the concatenation of two strings?

951


What do you mean by context of a subroutine?

922


What does this symbol mean '->'?

918


Why Perl aliases are considered to be faster than references?

899


Explain use of ‘my’ keyword in perl?

886


Explain the internal working of cgi

885


you are required to replace a char in a string and store the number of replacements. How would you do that?

860


Which functions in Perl allows you to include a module file or a module and what is the difference between them?

935


Explain about the applications of perl?

913


Explain gmtime() function in perl?

913


What are the features of perl language?

1021


What exactly is grooving and shortening of the array?

958


Write a program to decode the data in the form using cgi programming

987