scala怎么做幂运算_Scala幂(幂)函数示例

scala怎么做幂运算

Scala programming language has a huge set of libraries to support different functionalities.

Scala编程语言具有大量的库来支持不同的功能。

scala.math.pow() (scala.math.pow())

The pow() function is used for the exponential mathematical operation,

pow()函数用于指数数学运算,

This method can be accessed from scala.math library directly. The function accepts two variables First number and second the power of the number up to which date exponent is to be found. And, it returns a double integer with the result of the exponential function.

可以直接从scala.math库访问此方法。 该函数接受两个变量,第一个是数字,第二个是要找到其日期指数的数字的幂。 并且,它返回带指数函数结果的双精度整数。

Let us see, the usage of pow() function and how to implement this into a Scala program?

让我们看看pow()函数用法以及如何将其实现到Scala程序中?

Example 1: Program to find square of a number in Scala

示例1:在Scala中查找数字平方的程序

object myClass{    
def main(args: Array[String]) {
var i = 5; 
var p = 2; 
var ans = scala.math.pow(i,p)
println("The value of "+i+" to the power of "+p+" is "+ ans)
}
}

Output

输出量

The value of 5 to the power of 2 is 25.0

Code explanation:

代码说明:

The above code is to find the square of the given number. To the find square of a given number, we will pass 2 to the second value of the pow() function. which returns the numbers power 2 that is its square.

上面的代码是查找给定数字的平方。 为了找到给定数字的平方,我们将2传递给pow()函数的第二个值。 返回数字幂2的平方。

Example 2: Program to find square root of a number in Scala

示例2:在Scala中查找数字平方根的程序

object myClass{
def main(args: Array[String]) {
var i = 25; 
var p = 0.5; 
var ans = scala.math.pow(i,p)
println("The value of "+i+" to the power of "+p+" is "+ ans)
}
}

Output

输出量

The value of 25 to the power of 0.5 is 5.0

Code explanation:

代码说明:

The above code is used to find the square root of the given number. In this program, we have used the pow() function from the Scala library. the function takes two double values and return the double value as the output of the pow() function. To find the square root we have set the second value to 0.5, which gives the square root of the number. The square root is printed in the next line using the println statement.

上面的代码用于查找给定数字的平方根。 在此程序中,我们使用了Scala库中的pow()函数 。 该函数接受两个double值,并将double值返回为pow()函数的输出。 为了找到平方根,我们将第二个值设置为0.5 ,该值给出了数字的平方根。 使用println语句在下一行中打印平方根。

翻译自: https://www.includehelp.com/scala/power-exponentiation-function-with-example-in-scala.aspx.aspx

scala怎么做幂运算

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/380069.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

frame--转载

所谓框架便是网页画面分成几个框窗&#xff0c;同时取得多个 URL。只 要 <FRAMESET> <FRAME> 即可&#xff0c;而所有框架标记 要放在一个总起的 html 档&#xff0c;这个档案只记录了该框架 如何划分&#xff0c;不会显示任何资料&#xff0c;所以不必放入 <…

cobalt strick 4.0 系列教程(6)Payload Artifact 和反病毒规避

0x01 哲学 Strategic Cyber 责任有限公司会定期回答有关规避的问题。Cobalt Strike 是否能够绕过 AV 产品&#xff1f;它能绕过哪些 AV 产品&#xff1f;它多久检查一次&#xff1f; Cobalt Strike 默认的 Artifact 可能会被大多数终端安全解决方案拦截。规避不是 Cobalt Str…

【转】企业开发的困境与变局

原文&#xff1a;企业开发的困境与变局 文 / 刘江 算起来&#xff0c;《程序员》已经有几年时间没有大篇幅讨论企业软件开发这个话题了。这其实挺奇怪的。要知道&#xff0c;按类别来分&#xff0c;国内从事企业软件开发的技术人员是最多的&#xff0c;从CSDN和《程序员》联合举…

c# 类对象和实例对象_C#类和对象能力问题 套装4

c# 类对象和实例对象1) What are the correct statements about given code snippets? using System;public class Example{virtual private int X;private int Y;static void Main(string[] args){Console.WriteLine("Hello World");}}Hello WorldHelloWorldSyntax…

linkBar组件学习--设置linkBar子项的竖直间距.

效果&#xff1a;代码&#xff1a; <?xml version"1.0" encoding"utf-8"?><!--http://blog.flexexamples.com/2008/04/20/setting-the-vertical-spacing-between-items-in-a-linkbar-control-in-flex/ --><mx:Application xmlns:mx"…

AES算法

算法简介 AES本质是一种对称分组密码体制&#xff0c;采用代替/置换网络。每轮由三层组成&#xff1a;线性混合层确保多轮之上的高度扩散&#xff0c;非线性层由16个S盒并置起到混淆的作用&#xff0c;秘钥加密层将子秘钥异或到中间状态。 AES加密数据块和秘钥长度可以是128比…

C——结构体

例题1&#xff1a;(使用结构体) 输入两个学生的学号、姓名和成绩&#xff0c;输出成绩较高的学生的学号、姓名和成绩 解题思路&#xff1a; (1)定义连个结构相同的结构体变量student1,student2; (2)分别输入两个学生的学号、姓名、和成绩&#xff1b; (3)比较两个学生的成…

web.config配置文件详解

<?xml version"1.0"?> <!--注意: 除了手动编辑此文件以外&#xff0c;您还可以使用 Web 管理工具来配置应用程序的设置。可以使用 Visual Studio 中的“网站”->“Asp.Net 配置”选项。 设置和注释的完整列表在 machine.config.comments 中&#xff0c…

离散数学群论_离散数学中的群论及其类型

离散数学群论半群 (Semigroup) An algebraic structure (G, *) is said to be a semigroup. If the binary operation * is associated in G i.e. if (a*b) *c a *(b*c) a,b,c e G. For example, the set of N of all natural number is semigroup with respect to the operat…

IDA使用方法-----1

0x01 启动IDA new&#xff1a;反汇编一个新文件go&#xff1a;运行&#xff0c;直接进入IDAPrevious&#xff1a;载入一个我们以前编译过的程序 如果不想每次都看到这个对话框&#xff0c;可以取消该对话框底部的Display at startup&#xff08;启动时显示&#xff09;&#x…

邮箱验证JS代码

方法一,用JSfunction finish_onclick() { var username document.getElementById("username");var pwhidden document.getElementById("pwhidden");if(username.value"") { alert("请填写您的企业邮箱地址&#xff01;");username.f…

objdump命令详解

objdump命令是用查看目标文件或者可执行的目标文件的构成的gcc工具。 选项 --archive-headers -a 显示档案库的成员信息,类似ls -l将lib*.a的信息列出。 -b bfdname --targetbfdname 指定目标码格式。这不是必须的&#xff0c;objdump能自动识别许多格式&#xff0c;比如…

Java——异常(try...catch...finally)

public class Demo5_Throwable {public static void main(String[] args) {try{System.out.println(1/0);}catch(Exception e){System.out.println(e.getMessage());//获取异常信息,返回字符串&#xff1b;System.out.println(e.toString());//获取异常类名和异常信息&#xff…

Python程序反转给定数字(2种不同方式)

Take input number from the user and print its reverse. 从用户处获取输入号码并打印其反面。 Example: 例&#xff1a; Input:12345Output:54321Here, we are implementing program to reversing a given number using 2 different ways. 在这里&#xff0c;我们正在实施程…

外汇期货学习专帖(转)

一篇好文,值得深思! (转) 我的一些所看所想,和大家聊聊 ; d: R ^6 c* A2 e X" y8 y4 Bhttp://www.fx998.cn 说来惭愧,很久以前,俺在期货公司混事,95年以前国内期货公司从外盘棉花到咖啡....,外汇期指到原油.都能*作.是一派欣欣向荣之景.95年之后,按国家规定都转了内…

《Pro ASP.NET MVC 3 Framework》学习笔记之四【领域模型介绍】

主题&#xff1a;应用领域驱动开发(Applying Domain-Driven Development) Domain Model是MVC程序的"心脏"&#xff0c;其他的一切&#xff0c;包括Controllers和Views仅仅是用来跟Domain Model交互的一种方式&#xff0c;ASP.NET MVC并没有限制使用在Domain Model上面…

Java——集合框架(List)

集合框架&#xff08;List的三个子类的特点&#xff09; A&#xff1a;List的三个子类的特点 ArrayList&#xff1a; 底层数据结构是数组&#xff0c;查询快&#xff0c;增删慢。 线程不安全&#xff0c;效率高。 Vector&#xff1a; 底层数据结构是数组&#xff0c;查询…

一步一步学pwntools(适合新手)

序 pwntools是一个二进制利用框架。官方文档提供了详细的api规范。然而目前并没有一个很好的新手教程。因此我用了我过去的几篇writeup。由于本文只是用来介绍pwntools使用方法&#xff0c;我不会过于详细的讲解各种二进制漏洞攻击技术。 Pwntools的“Hello World” 栈溢出无…

关于J2EE中死锁问题的研究(1)

大多数重要的应用程序都涉及高度并发性和多个抽象层。并发性与资源争用有关&#xff0c;并且是导致死锁问题增多的因素之一。多个抽象层使隔离并修复死锁环境的工作变得更加困难。 通常&#xff0c;当同时执行两个或两个以上的线程时&#xff0c;如果每个线程都占有一个资源并请…

python变量分配内存_Python | 声明任何变量而不分配任何值

python变量分配内存Since, Python is a dynamic programming language so there is no need to declare such type of variable, it automatically declares when first time value assign in it. 由于Python是一种动态编程语言&#xff0c;因此无需声明此类变量&#xff0c;它…