Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.
Prime no's pgm
Name: spani Date: February 28, 2009 at 00:03:35 Pacific OS: Windows XP CPU/Ram: 2.00Ghz Product: Hcl DESKTOP Subcategory: Java
Comment:
//java pgm to print prime no's upto given integer
import java.util.Scanner; class Primes { int c,n,s,i,j,x; int k=0; void getData() { Scanner ip=new Scanner(System.in); System.out.println("Enter n value"); n=ip.nextInt(); System.out.println("Primes are "+2); } void makePrimes() { for(int i=2;i<=n;i++) { if(i%2!=0) { s=(int)Math.sqrt(i)+1; for(int j=2;j<=s&&j!=i;j+=2) { c=i%j; if(c==0) { k++; break; } } if(k==0) display(i); } } } void display(int x) { System.out.println(x); } } class PrimeNum { public static void main(String args[]) { Primes A=new Primes(); A.getData(); A.makePrimes(); } }
Plz tell me wats wrong with this pgm in the o/p of the pgm it is showing the non primes as primes
Summary: Hi, please help me... im trying to write a program that accepts 2 16-bit binary in 0's and 1's and adds the two no's and displays the result in binary. 2. wants to convert the two binary no's and the...
Summary: Thanks Very Much For Your Code...It Is Very Very Fast. Still you are checking every number as I am except you start at the begining of your array (the low end) and I was starting at the end (the high...
Summary: i am tryimg to write a java program to check input no.to se if it is a prime no. I have to request a positive no. input and then loop through the formula(i=2;i*i=n;i++) n=input no.Any assistance welco...