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.pswp.cn/news/380069.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/380069.shtml
英文地址,請注明出處:http://en.pswp.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;它…