日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

kotlin 第一个程序_Kotlin程序添加两个矩阵

發布時間:2023/12/1 编程问答 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 kotlin 第一个程序_Kotlin程序添加两个矩阵 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

kotlin 第一個程序

Given two matrices, we have to add them.

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

Example:

例:

Input:matrix 1:[2, 3][4, 5][7, 1]matrix 2:[4, 6][9, 0][7, 6]Output:[6, 9][13, 5][14, 7]

在Kotlin中添加兩個矩陣的程序 (Program to add two matrices in Kotlin)

package com.includehelpimport java.util.*// Main function, Entry Point of Program fun main(args: Array<String>) {//variable of rows and colval rows: Intval column: Int//Input Streamval scanner = Scanner(System.`in`)//Input no of rows and columnprint("Enter the number of rows and columns of matrix : ")rows = scanner.nextInt()column = scanner.nextInt()//Create Arrayval matrixA = Array(rows) { IntArray(column) }val matrixB = Array(rows) { IntArray(column) }val matrixSum = Array(rows) { IntArray(column) }//Input Matrixprintln("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 Matrixprintln("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 Aprintln("Matrix A : ")for(i in matrixA.indices){println("${matrixA[i].contentToString()} ")}//print Matrix Bprintln("Matrix B : ")for(i in matrixB.indices){println("${matrixB[i].contentToString()} ")}//Perform Additionfor(i in matrixSum.indices){for(j in matrixSum[i].indices){matrixSum[i][j]=matrixA[i][j]+matrixB[i][j]}}//Print Sum of Matricesprintln("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 2 Enter the Elements of First Matrix (3 X 2} ): matrixA[0][0]: 2 matrixA[0][1]: 3 matrixA[1][0]: 4 matrixA[1][1]: 5 matrixA[2][0]: 7 matrixA[2][1]: 1 Enter the Elements of Second Matrix (3 X 2} ): matrixB[0][0]: 4 matrixB[0][1]: 6 matrixB[1][0]: 9 matrixB[1][1]: 0 matrixB[2][0]: 7 matrixB[2][1]: 6 Matrix A : [2, 3] [4, 5] [7, 1] Matrix B : [4, 6] [9, 0] [7, 6] Sum of the Matrices: [6, 9] [13, 5] [14, 7] --------------- Run 2: 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]: 4 matrixA[1][0]: 5 matrixA[1][1]: 6 matrixA[1][2]: 7 matrixA[2][0]: 0 matrixA[2][1]: 9 matrixA[2][2]: -7 Enter the Elements of Second Matrix (3 X 3} ): matrixB[0][0]: 4 matrixB[0][1]: 0 matrixB[0][2]: -6 matrixB[1][0]: -3 matrixB[1][1]: 2 matrixB[1][2]: 3 matrixB[2][0]: 4 matrixB[2][1]: 5 matrixB[2][2]: 6 Matrix A : [2, 3, 4] [5, 6, 7] [0, 9, -7] Matrix B : [4, 0, -6] [-3, 2, 3] [4, 5, 6] Sum of the Matrices: [6, 3, -2] [2, 8, 10] [4, 14, -1]

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

kotlin 第一個程序

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的kotlin 第一个程序_Kotlin程序添加两个矩阵的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。