这是实现质数的算法发现在Java中的最佳方式是什么?我们如何让库类和使用,然后在Java中? [英] Which is the best way to implement prime number finding algorithms in Java? How do we make library classes and use then in Java?

查看:148
本文介绍了这是实现质数的算法发现在Java中的最佳方式是什么?我们如何让库类和使用,然后在Java中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使库Java中的类,并利用它们在我未来的计划。我想这些类库找到素数高达一定数量,甚至下一个素数,或者你可以说解决了大部分的基本相关素数的事情。

I want to make library classes in Java and use them in my future programs. I want these library classes to find prime numbers upto a certain number or even the next prime number or you can say solve most of the basic things related to prime numbers.

  1. 我从来没有打过一个Java库类。我的目标是学习,这样做。请帮我不认为通过指出教程什么的。我所熟悉的NetBeans IDE中。
  2. 在我发现了一些算法,如埃拉托色尼的筛的阿特金的筛。这将是巨大的,如果你能点出几个这样的高效算法。我不希望他们是最好的,但至少不够好。我的目标是通过实现他们学习一些东西。因为我没有多大实际编码经验,我想这样做,以提高我的技能。
  3. 在我的朋友建议我使用流类和他谈论一些关于通过给一个文件的输出作为输入到另一个让我的code干净实现它。我不明白他很好。请原谅我,如果我说任何事。我想问一下在这一点上是什么,就是做我想做的事情的一种高效和面向对象的方式。如果有,请告诉我该怎么做,如果没有,请指出一些其他的方式来做到这一点。
  1. I have never made a Java Library Class. I aim to learn that doing this. Please help me without that by pointing out a tutorial or something. I am familiar with netbeans IDE.
  2. I found out a few algorithms like Sieve of Eratosthenes and Sieve of Atkin. It would be great if you can point out a few more such efficient algorithms. I don't want them to be the best but at least good enough. My aim is to learn few things by implementing them. Because I have little practical coding experience I want to do it to improve my skills.
  3. My friend suggested me to use Stream Classes and he was talking something about implementing it by giving the output of one file as an input to another to make my code clean. I didn't understand him very well. Please pardon me if i said anything wrong. What I want to ask in this point is, is that an efficient and OO way of doing what i want to do. If yes please tell me how to do that and if not please point out some other way to do it.

我对Java语言的基本知识。我想做到通过这家合资公司是增益的编码经验,因为这是每个人都在这里提出,拿起小东西像这样的学习对我自己的

I have basic knowledge of the Java language. What I want to accomplish through this venture is gain coding experience because that is what everyone out here suggested, "to take up small things like these and learn on my own"

感谢大家提前

关于

shahensha

shahensha

编辑: 在埃拉托塞尼和他人的筛我们需要从2存储的数字到n中的数据结构。我应该在哪里存放呢?我知道我可以使用一个动态集合,但只是一个小问题......如果我想找到素数百亿的订单,甚至更多(我将使用大整数毫无疑问的),但是这一切都将得到存储在堆中对?有没有担心溢出?即使它不会是一个好的做法呢?或者会是更好的存储数字或列表(上,我们将执行取决​​于我们使用的算法动作)在一个文件中,并访问它呢?很抱歉,如果我的问题是太noobish ...

In the Sieve of Eratosthenes and others we are required to store the numbers from 2 to n in a data structure. Where should I store it? I know I can use a dynamic Collection, but just a small question...If i want to find primes in the order of billions or even more (I will use Big Integer no doubt), but all this will get stored in the heap right? Is there a fear of overflow? Even if it doesn't will it be a good practice? Or would it be better to store the numbers or the list (on which we will perform actions depending on the algorithm we use) in a file and access it there? Sorry if my question was too noobish...

推荐答案

埃拉托色尼的筛子还是不错的算法来寻找素数。如果你使用谷歌,你可以找到<一href="http://www.google.ru/search?hl=ru&source=hp&biw=1680&bih=917&q=Sieve+of+Eratosthenes+java&aq=f&aqi=&aql=&oq=&gs_rfai="相对=nofollow>准备实施的Java 。

"Sieve of Eratosthenes" is good algorithm to find the prime numbers. If you will use google you can find ready implementation in java.

这篇关于这是实现质数的算法发现在Java中的最佳方式是什么?我们如何让库类和使用,然后在Java中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆