QuestionAsk Questions?

View Answers

January 12, 2009 at 11:21 PM

Hi friend,

Code to help in solving the problem :

import java.io.*;

class PrimeNumber {

public static void main(String[] args) throws Exception{

int i;

BufferedReader bf = new BufferedReader(

new InputStreamReader(System.in));

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

int num = Integer.parseInt(bf.readLine());

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

for (i=1; i < num; i++ ){

int j;

for (j=2; j<i; j++){

int n = i%j;

if (n==0){

break;

}

}

if(i == j){

System.out.print(" "+i);

}

}

}

}

Thanks

Code to help in solving the problem :

import java.io.*;

class PrimeNumber {

public static void main(String[] args) throws Exception{

int i;

BufferedReader bf = new BufferedReader(

new InputStreamReader(System.in));

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

int num = Integer.parseInt(bf.readLine());

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

for (i=1; i < num; i++ ){

int j;

for (j=2; j<i; j++){

int n = i%j;

if (n==0){

break;

}

}

if(i == j){

System.out.print(" "+i);

}

}

}

}

Thanks

January 13, 2009 at 12:19 AM

Hi friend,

import java.io.*;

class PrimeDemo {

public static void main(String[] args) throws Exception{

int i;

BufferedReader buff = new BufferedReader(new InputStreamReader(System.in));

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

int num = Integer.parseInt(buff.readLine());

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

for (i=1; i < num; i++ ){

int j;

for (j=2; j<i; j++){

int n = i%j;

if (n==0){

break;

}

}

if(i == j){

System.out.print(" "+i);

}

}

}

}

--------------------------------

Visit for more information:

http://www.roseindia.net/java/

Thanks.

import java.io.*;

class PrimeDemo {

public static void main(String[] args) throws Exception{

int i;

BufferedReader buff = new BufferedReader(new InputStreamReader(System.in));

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

int num = Integer.parseInt(buff.readLine());

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

for (i=1; i < num; i++ ){

int j;

for (j=2; j<i; j++){

int n = i%j;

if (n==0){

break;

}

}

if(i == j){

System.out.print(" "+i);

}

}

}

}

--------------------------------

Visit for more information:

http://www.roseindia.net/java/

Thanks.

Related Tutorials/Questions & Answers:

Advertisements