473,385 Members | 1,615 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How it improve

I made this program test prime.
I want it improve I have idea but I don’t now how it insert in into program.
Howe somebody else idea?


My idea: if(prime[i]==true)
i*i==false;
Thank for your help


public class testPrime{
public static void main(String[] args) {

int limit = 1000;
int i,j;
boolean []prime=new boolean[limit+1];

for( i=1;i<=limit;i++){
prime[i]=true;

if(i%2==0)
prime[i]=false;

if((i%3==0)||(i%5==0))
prime[i]=false;

prime[1]=true;
prime[2]=true;
prime[3]=true;
prime[5]=true;

if(prime[i]==false)
continue;

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

if(i%j==0)
prime[i]=false;

}
if(prime[i]==true)
System.out.println(i+" is_prime**");
else
System.out.println(i+" no_prime");
}
}
}
Nov 8 '06 #1
4 1324
r035198x
13,262 8TB
I made this program test prime.
I want it improve I have idea but I don’t now how it insert in into program.
Howe somebody else idea?


My idea: if(prime[i]==true)
i*i==false;
Thank for your help


public class testPrime{
public static void main(String[] args) {

int limit = 1000;
int i,j;
boolean []prime=new boolean[limit+1];

for( i=1;i<=limit;i++){
prime[i]=true;

if(i%2==0)
prime[i]=false;

if((i%3==0)||(i%5==0))
prime[i]=false;

prime[1]=true;
prime[2]=true;
prime[3]=true;
prime[5]=true;

if(prime[i]==false)
continue;

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

if(i%j==0)
prime[i]=false;

}
if(prime[i]==true)
System.out.println(i+" is_prime**");
else
System.out.println(i+" no_prime");
}
}
}
Now hold it right there.

From here,
Expand|Select|Wrap|Line Numbers
  1.  
  2. Now hold it right there. 
  3. public class testPrime{
  4. public static void main(String[] args) {
  5. int limit = 1000;
  6. int i,j;
  7. boolean []prime = new boolean[limit+1];
  8. for( i=2;i<=limit;i++){
  9. prime[i]=true;
  10.  
  11.  
  12. for( j=2;j<i;j++){
  13. if(i%j == 0)
  14. prime[i]=false;
  15. }
  16. if(prime[i]==true)
  17. System.out.println(i+" is_prime**");
  18. else
  19. System.out.println(i+" no_prime");
  20. }
  21. }
  22. }
  23.  
Go to
http://www.troubleshooters.com/codec...imenumbers.htm
and
http://www.freevbcode.com/ShowCode.asp?ID=1059

Hope you can follow the algorithms here because they were not written in java.
Nov 8 '06 #2
I want only discart multiple of prime numbers before second loop = i*i
I don't know how to do it in array.
Nov 8 '06 #3
try to use this
this gives the whole list of prime nos till the limil value
Expand|Select|Wrap|Line Numbers
  1. public static void main(String[] args) {
  2.         int length=1000;
  3.         boolean []prime=new boolean[length+1];
  4.         prime[0]=prime[1]=prime[2]=true;
  5.     for(int j=3;j<=length;j++)
  6.     {
  7.         prime[j]=true;
  8.         for(int k=2;k<j;k++)
  9.         {
  10.             if(j%k==0)
  11.             {
  12.                 prime[j]=false;
  13.                 break;
  14.             }
  15.         }
  16.  
  17.     }
  18.     for(int i=0;i<length;i++)
  19.     {
  20.         System.out.println(i+"   "+prime[i]);
  21.     }
  22.  
Nov 8 '06 #4
Thank for your help.
Nov 8 '06 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Allyson Griffin | last post by:
--__A455_55B08..702A Content-Type: text/html; Content-Transfer-Encoding: quoted-printable <html>helloooo Men improve your LUV life with these nohc <br> <body> <br>Quality purr^scriptions for...
10
by: pembed2003 | last post by:
Hi all, I asked this question in the C group but no one seems to be interested in answering it. :-( Basically, I wrote a search and replace function so I can do: char source = "abcd?1234?x";...
3
by: Anand | last post by:
Hi Iam keen interested to improve my skills in c programming. Now Iam familiar with all the syntax and concepts. My main idea is to know how entire c compiler behaves in all circumstances(i.e...
9
by: Peng Jian | last post by:
I have a function that is called very very often. Can I improve its efficiency by declaring its local variables to be static?
6
by: Jéjé | last post by:
Hi, hoew can I improve the compilation process of a sharepoint website? my server is: 2 * P3 Xeom 1ghz 4go ram 2 * 36gb (mirror for OS and website) 2 * 36 Raid 0 (stripping; for temp files...
0
by: Laurence Parry | last post by:
Some people over on Wikipedia seem to have the idea that VB.NET is not a major programming language: http://en.wikipedia.org/wiki/Template_talk:Major_programming_languages_small#Visual_Basic_.NET ...
2
by: swannyfeng | last post by:
I have the idea about the web engine, it can improve the experience for the web searcher I have the idea about the web engine, it can improve the experience for the web searcher But I don't...
16
by: weidongtom | last post by:
Hi, I have just finished reading some tutorials on C, I am wondering how I could improve my skill. Is there any advice? Is reading others' codes the best way? If so, what type of codes are...
11
by: Peted | last post by:
Im using c# 2005 express edition Ive pretty much finished an winforms application and i need to significantly improve the visual appeal of the interface. Im totaly stuck on this and cant seem...
2
by: sdanda | last post by:
Hi , Do you have any idea how to improve my java class performance while selecting and inserting data into DB using JDBC Connectivity ......... This has to work for more than 8,00,000...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.