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 第一个程序

kotlin 第一个程序_Kotlin程序减去两个矩阵相关推荐

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

    kotlin 第一个程序 Given two matrices, we have to add them. 给定两个矩阵,我们必须将它们相加. Example: 例: Input: matrix 1: ...

  2. kotlin创建静态单利_Kotlin程序来计算单利

    kotlin创建静态单利 Given, principal, rate, and time, we have to calculate the simple interest. 给定本金,利率和时间, ...

  3. kotlin中判断字符串_Kotlin程序查找字符串中字符的频率

    kotlin中判断字符串 Given a string and a character, we have to find the frequency of the character in the s ...

  4. kotlin半生对象_Kotlin程序| 随播对象特征

    kotlin半生对象 伴侣对象 (Companion object) If you need a function or a property to be tied to a class rather ...

  5. kotlin 类和对象_Kotlin程序| 类和对象的示例(带有学生数据)

    kotlin 类和对象 In the below program, we are creating a student class to input and print the student dat ...

  6. kotlin中判断字符串_Kotlin程序删除字符串中所有出现的字符

    kotlin中判断字符串 Given a string and a character, we have to remove all occurrences of the character in g ...

  7. kotlin 编译时常量_Kotlin程序| 编译时常量示例

    kotlin 编译时常量 编译时常数 (Compile-time Constant) If the value of a read-only (immutable) property is known ...

  8. kotlin 16进制_Kotlin程序将八进制数转换为十进制数

    kotlin 16进制 Given a number in octal number system format, we have to convert it into decimal number ...

  9. kotlin 字符串去空格_Kotlin程序从字符串中删除所有空格

    kotlin 字符串去空格 Given a string, we have to remove all whitespaces from it. 给定一个字符串,我们必须从中删除所有空格. Examp ...

最新文章

  1. 100%的BAT招聘岗位都考的知识,你精通了吗?
  2. 高压缩比 压缩软件 linux,Linux下压缩软件对比
  3. 时间日期格式转换_JAVA
  4. 获取3的倍数_获取和设置pdf目录
  5. 我终于搞清楚了和String有关的那点事儿
  6. 在成长中遇到的挫折事件对你的影响_多种语言环境中成长的宝宝,会影响说话早晚?其实没有想象的复杂...
  7. 11月TIOBE编程语言排行榜,OC已经掉出前十
  8. VMware vCenter Server 的内部版本号和版本 (2143838)
  9. LeetCode 142. 环形链表 II(Linked List Cycle II)
  10. Python爬虫之(六)requests库的用法
  11. Win10下VB6.0开发之错误--无法打开对象窗口和代码窗口
  12. T-SQL行合并成列与列拆分成行
  13. 使用DbFunctions来解决EF按照日期分组数据
  14. Finding distance between two curves
  15. 自学-Linux-老男孩Linux77期-day7
  16. 使用Python自动完成Himawari-8(葵花8)卫星AOD数据下载与解析(转TIFF)
  17. 秦偲洺 荣获 火星少年计划 第三季 全球线上评选人气奖
  18. c语言编程八卦方位,易经手掌八卦图,如何C语言编程画一个彩色的周易八卦图...
  19. 液晶电视面板的类型、等级及鉴别方法
  20. MongoDB 简单实践入门

热门文章

  1. 编译原理简单语法分析器(first,follow,分析表)源码下载
  2. Linux、Mac 命令行快捷键
  3. 计算机语言低下限高上限,学习语言有没有上限
  4. python集合去重_python集合去重
  5. AJAX框架衣柜内部布局,​最合理的衣柜内部布局解析,3大细节不容小觑
  6. Python-import导入上级 本级 目录文件
  7. #2002 - 服务器没有响应 (or the local MySQL server's socket is not ...
  8. ubuntu7.10下的vi用的怪怪的
  9. X86和X86_64和AMD64的由来
  10. Android4.0设置界面修改总结