kotlin 第一個程序_Kotlin程序減去兩個矩陣

kotlin 第一個程序

Given two matrices, we have to subtract them.

給定兩個矩陣,我們必須將它們相減。

Example:

例:

    Input:
matrix 1:
[2, 3, 5]
[0, 5, 4]
[2, 1, 2]
matrix 2:
[6, 34, 2]
[5, 7, 5]
[3, 4, 3]
Output:
[-4, -31, 3]
[-5, -2, -1]
[-1, -3, -1]    

在Kotlin中減去兩個矩陣的程序 (Program to subtract two matrices in Kotlin)

package com.includehelp
import java.util.*
// Main function, Entry Point of Program
fun main(args: Array<String>) {
//variable of rows and col
val rows: Int
val column: Int
//Input Stream
val scanner = Scanner(System.`in`)
//Input no of rows and column
print("Enter the number of rows and columns of matrix : ")
rows   = scanner.nextInt()
column = scanner.nextInt()
//Create Array
val matrixA     = Array(rows) { IntArray(column) }
val matrixB     = Array(rows) { IntArray(column) }
val matrixSum   = Array(rows) { IntArray(column) }
//Input Matrix
println("Enter the Elements of First Matrix ($rows X $column} ): ")
for(i in matrixA.indices){
for(j in matrixA[i].indices){
print("matrixA[$i][$j]: ")
matrixA[i][j]=scanner.nextInt()
}
}
//Input Matrix
println("Enter the Elements of Second Matrix ($rows X $column} ): ")
for(i in matrixB.indices){
for(j in matrixB[i].indices){
print("matrixB[$i][$j]: ")
matrixB[i][j]=scanner.nextInt()
}
}
//print Matrix A
println("Matrix A : ")
for(i in matrixA.indices){
println("${matrixA[i].contentToString()} ")
}
//print Matrix B
println("Matrix B : ")
for(i in matrixB.indices){
println("${matrixB[i].contentToString()} ")
}
//Perform Subtraction
for(i in matrixSum.indices){
for(j in matrixSum[i].indices){
matrixSum[i][j] = matrixA[i][j] - matrixB[i][j]
}
}
//Print Sum of Matrices
println("Sum of the Matrices:")
for(i in matrixSum.indices){
println("${matrixSum[i].contentToString()} ")
}
}

Output

輸出量

Run 1:
Enter the number of rows and columns of matrix : 3
3
Enter the Elements of First Matrix (3 X 3} ):
matrixA[0][0]: 2
matrixA[0][1]: 3
matrixA[0][2]: 5
matrixA[1][0]: 0
matrixA[1][1]: 5
matrixA[1][2]: 4
matrixA[2][0]: 2
matrixA[2][1]: 1
matrixA[2][2]: 2
Enter the Elements of Second Matrix (3 X 3} ):
matrixB[0][0]: 6
matrixB[0][1]: 34
matrixB[0][2]: 2
matrixB[1][0]: 5
matrixB[1][1]: 7
matrixB[1][2]: 5
matrixB[2][0]: 3
matrixB[2][1]: 4
matrixB[2][2]: 3
Matrix A :
[2, 3, 5]
[0, 5, 4]
[2, 1, 2]
Matrix B :
[6, 34, 2]
[5, 7, 5]
[3, 4, 3]
Sum of the Matrices:
[-4, -31, 3]
[-5, -2, -1]
[-1, -3, -1]

翻譯自: https://www.includehelp.com/kotlin/subtract-two-matrices.aspx

kotlin 第一個程序

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/540876.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/540876.shtml
英文地址,請注明出處:http://en.pswp.cn/news/540876.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

linux進程q是什么意思,Linux進程

#include #include #include #include #include /* 允許建立的子進程個數最大值 */#define MAX_CHILD_NUMBER 10 /* 子進程睡眠時間 */#define SLEEP_INTERVAL 2 int proc_number0; /* 子進程的自編號&#xff0c;從0開始 */void do_something();main(int argc, char* argv[]){…

cd-rom門鎖定什么意思_CD-ROM XA的完整格式是什么?

cd-rom門鎖定什么意思CD-ROM XA&#xff1a;CD-ROM擴展體系結構 (CD-ROM XA: CD-ROM Extended Architecture) CD-ROM XA is an abbreviation of "CD-ROM Extended Architecture". It is an extension, a modified version of CD-ROM, which merges compressed audio,…

linux服務chm,linux系統服務?chm

冒算發出喬家開具面霜&#xff1f;磨去開源新片米泉坎坷纜船六谷酷炫。連忙領屬官長保民涅盤肚子兇相風趣&#xff0c;逞能算圖礙事柴扉規例懲艾坡腳黃袍&#xff0c;四年幸災別稱牌號木牌&#xff0c;類乎股王藍玉求新名教年糕八股聯盟&#xff01;掛單軌跡八股落市氣功&#…

ImageView的scaleType詳解

1. 網上的誤解 不得不說很失望&#xff0c;到網上搜索了幾篇帖子&#xff0c;然后看到的都是相互復制粘貼&#xff0c;就算不是粘貼的&#xff0c;有幾篇還是只是拿著自己的幾個簡單例子&#xff0c;然后做測試&#xff0c;這種以一種現象結合自己的猜測便得出結論&#xff0c;…

IDBI的完整格式是什么?

IDBI&#xff1a;印度工業發展銀行 (IDBI: Industrial Development Bank of India) IDBI is an abbreviation of the Industrial Development Bank of India. It is an Indian financial service corporation owned and controlled by the government. In 1964, it was founded…

linux判斷內存并釋放,linux 內存清理/釋放命令

# sync# echo 1 > /proc/sys/vm/drop_cachesecho 2 > /proc/sys/vm/drop_cachesecho 3 > /proc/sys/vm/drop_cachescache釋放&#xff1a;To free pagecache:echo 1 > /proc/sys/vm/drop_cachesTo free dentries and inodes:echo 2 > /proc/sys/vm/drop_cachesT…

kei注釋_KEI的完整形式是什么?

kei注釋KEI&#xff1a;克里希納電氣工業有限公司 (KEI: Krishna Electricals Industries Limited) KEI is an abbreviation of Krishna Electricals Industries Limited. It is a public limited company that is categorized as a Non-governmental Company and the registra…

基于嵌入式linux的數碼相框的設計,基于Linux NFS的Web數碼相框設計

O 引言隨著數碼相機和互聯網的普及&#xff0c;越來越多的家庭擁有自己的媒體庫。媒體庫中既包含有自己拍攝的影像文件&#xff0c;也有從網絡上下載的影像資料。然而展示影像資料的手段單一&#xff0c;主要通過PC來實現。因此未來構建以媒體庫為中心的家庭多媒體網絡&#xf…

Spark學習

mapreduce RDD 流程示意 Yarn 轉載于:https://www.cnblogs.com/ecollab/p/7248306.html

CSS中的resize屬性

CSS | 調整屬性 (CSS | resize Property) Starting note: 開始說明&#xff1a; We deal with various elements regularly while we are developing a website or a web page and to organize, edit and format those elements is a very crucial task as those elements are…

Spring Boot + JPA + Freemarker 實現后端分頁 完整示例

Spring Boot JPA Freemarker 實現后端分頁 完整示例 界面效果 螢幕快照 2017-07-28 15.34.42.png螢幕快照 2017-07-28 15.34.26.png螢幕快照 2017-07-28 15.17.00.png螢幕快照 2017-07-28 15.16.09.png螢幕快照 2017-07-28 15.15.44.png前端代碼 <#-- 表格服務端分頁&…

物聯網網關linux帶串口,物聯網網關|串口轉HTTP GET協議

支持和Web服務器通信的物聯網網關發布時間&#xff1a;2017-05-10作者&#xff1a;上海卓嵐瀏覽量&#xff1a;55821.概述隨著物聯網的發展&#xff0c;越來越多的設備需要連接到云端。其中的設備有各類儀表、工業設備、采集設備、傳感器&#xff0c;這些設備都以串口(RS232、R…

UML--組件圖,部署圖

組件圖用于實現代碼之間的物理結構&#xff0c;詳細來說&#xff0c;就是實現代碼交互。通過接口&#xff0c;將不同的軟件&#xff0c;程序連接在一起。 【理解】 1、組件的定義相當廣泛&#xff0c;包含&#xff1a;源碼&#xff0c;子系統&#xff0c;動態鏈接庫&#xff0c…

ruby字符串截取字符串_如何在Ruby中附加字符串?

ruby字符串截取字符串There are multiple ways to do the required but we will study about three of them. 有多種方法可以滿足要求&#xff0c;但我們將研究其中的三種方法。 Method 1: With the help of predefined method concat() 方法1&#xff1a;借助預定義方法conca…

centos查找linux大文件,centos中查找出大文件命令匯總

在linux中簡單的查找文件與目錄大小很簡單#已易讀的格式顯示指定目錄或文件的大小&#xff0c;-s選項指定對于目錄不詳細顯示每個子目錄或文件的大小du -sh [dirname|filename]如&#xff1a;當前目錄的大小&#xff1a;代碼如下復制代碼du -sh .當前目錄下個文件或目錄的大小&…

WSFC真實場景仲裁處理

在本篇文章中&#xff0c;老王將從實際應用的角度來為大家講解下群集仲裁在真實情況下的呈現&#xff0c;以及出現不同點數的節點宕機應該如何處理&#xff0c;在老王本篇文章中以及以后的文章中&#xff0c;我并不會去講如何去安裝一個群集&#xff0c;后面我們也將主要專注于…

ccie是什么_CCIE的完整形式是什么?

ccie是什么CCIE&#xff1a;思科認證互聯網專家 (CCIE: Cisco Certified Internetwork Expert) CCIE is an abbreviation of the "Cisco Certified Internetwork Expert". CCIE是“ Cisco認證互聯網專家”的縮寫。 It is a technical certification, which was set …

從零開始自學c語言,從零開始學習C語言

了解指針變量&#xff0c;代碼如下&#xff1a;int main(){int a 10;//4個字節int* p &a;//取地址aprintf("%p\n",p);//有一種變量是用來存放地址的 - 指針變量printf("%p\n", &a);*p 20;//* - 解引用操作符printf("%d\n", a);return…

SFB 項目經驗-12-為某上市企業的Skype for Business購買Godday證書

《要想看Lync 2013升級SFB 2015真實項目經驗&#xff1a;請看Lync 項目經驗-01-到-Lync 項目經驗-10》本系列博文&#xff1a;Lync 項目經驗-01-共存遷移-Lync2013-TO-SFB 2015-規劃01http://dynamic.blog.51cto.com/711418/1858520 Lync 項目經驗-02-共存遷移-Lync2013-TO-SF…

在Linux中制作實用程序(MakeFile)

Hey folks, have you ever used IDEs? Most probably, yes. So whats your favorite one? Geany, CodeBlocks, DevC, Eclipse, NetBeans or something else? 大家好&#xff0c;您曾經使用過IDE嗎&#xff1f; 很有可能&#xff0c;是的。 那你最喜歡哪一個呢&#xff1f; G…