我如何可以使用Apache的数学与Scala呢? [英] how can I use apache math with scala?

查看:104
本文介绍了我如何可以使用Apache的数学与Scala呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Apache数学与斯卡拉,但我无法从文档的 http://commons.apache.org/proper/commons-math/userguide/random.html

I am trying to use apache math with scala but I am not able to run the examples from the documentation http://commons.apache.org/proper/commons-math/userguide/random.html

import math._


object Hello extends App {

  println("HELLO")

  RandomDataGenerator randomData = new RandomDataGenerator(); 
  //not found: value RandomDataGenerator
}

我是新来斯卡拉和Java,所以请提供详细的解答。

I am new to scala and java so please provide a detailed answer.

编辑:
我创建的新文件夹build.sbt 。如果我运行命令 SBT该文件夹超过code控制台似乎在控制台中工作。
但现在我怎么能可以运行在Eclipse中code?

I have created a new folder with the build.sbt. If I run the command sbt console in that folder than the code seems to be working in the console. But now how can I can run the code on eclipse??

推荐答案

Apache项目文档往往是的可怕的有关解释如何开始。例如,你会看到下载无处不在,告诉你如何让项目code和罐子的链接。不要这样做!使用正确的构建系统将管理你的依赖你。在这个例子中,我将使用 SBT ,但Maven的将有更多的冗长工作一样好(尽管)。

Apache project documentation tends to be terrible about explaining how to get started. For example, you'll see "Download" links everywhere that show you how to get the project code and jars. Don't do this! Use a proper build system that will manage your dependencies for you. For this example I'll use SBT, but Maven would work just as well (although with a lot more verbosity).

一旦你得到了SBT安装可以搜索Maven的中央的公地数学,这将带你这里。你会看到一个侧面的斯卡拉SBT按钮;单击它,将文本复制到一个名为 build.sbt

Once you've got SBT installed you can search Maven Central for "commons-math", which will take you here. You'll see a "Scala SBT" button on the side; click it and copy the text to a file called build.sbt:

libraryDependencies += "org.apache.commons" % "commons-math3" % "3.3"

好了,现在你可以开始使用 SBT控制台的SBT控制台。现在,你需要知道的完整路径到你想要的类,这当然是无处Apache文档中可以找到,因为那将是太方便了。随着谷歌搜索,你会发现下面的一点点:

Okay, now you can start an SBT console with sbt console. Now you need to know the full path to the class you want, which of course is nowhere to be found in the Apache documentation, because that would be too convenient. With a little bit of Googling you'll find the following:

import org.apache.commons.math3.random.RandomDataGenerator

现在你可以创建一个实例:

And now you can create an instance:

object Hello extends App {
  println("HELLO")

  val randomData = new RandomDataGenerator()

  println(randomData.nextLong(0, 100))
}

和大功告成!现在,任何好的斯卡拉资源会给你如何完成任何你下一步想做的想法。

And you're done! Now any good Scala resource will give you an idea of how to accomplish whatever you want to do next.

这篇关于我如何可以使用Apache的数学与Scala呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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