kotlin 查找id_Kotlin程序在矩阵中查找偶数和奇数的频率
kotlin 查找id
Given a matrix, we have to find frequencies of even and odd numbers.
给定一个矩阵,我们必须找到偶数和奇数的频率。
Example:
例:
Input:
matrix:
[4, 5]
[6, 0]
[9, 2]
Output:
Even Elements Frequency : 4
Odd Elements Frequency : 2
在Kotlin中寻找矩阵中偶数和奇数频率的程序 (Program to find frequencies of even and odd numbers in a matrix 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
var oddCount = 0
var evenCount = 0
//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) }
//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()
//count Odd and Even elements Frequency
if(matrixA[i][j]%2==0) evenCount++ else oddCount++
}
}
//print Matrix A
println("Matrix A : ")
for(i in matrixA.indices){
println("${matrixA[i].contentToString()} ")
}
//Print Frequency
println("Even Elements Frequency : $evenCount")
println("Odd Elements Frequency : $oddCount")
}
Output
输出量
Run 1:
Enter the number of rows and columns of matrix : 2
4
Enter the Elements of First Matrix (2 X 4} ):
matrixA[0][0]: 3
matrixA[0][1]: 4
matrixA[0][2]: 5
matrixA[0][3]: 7
matrixA[1][0]: 0
matrixA[1][1]: 9
matrixA[1][2]: 1
matrixA[1][3]: -4
Matrix A :
[3, 4, 5, 7]
[0, 9, 1, -4]
Even Elements Frequency : 3
Odd Elements Frequency : 5
-----------
Run 2:
Enter the number of rows and columns of matrix : 3
2
Enter the Elements of First Matrix (3 X 2} ):
matrixA[0][0]: 4
matrixA[0][1]: 5
matrixA[1][0]: 6
matrixA[1][1]: 0
matrixA[2][0]: 9
matrixA[2][1]: 2
Matrix A :
[4, 5]
[6, 0]
[9, 2]
Even Elements Frequency : 4
Odd Elements Frequency : 2
翻译自: https://www.includehelp.com/kotlin/find-frequencies-of-even-and-odd-numbers-in-a-matrix.aspx
kotlin 查找id
kotlin 查找id_Kotlin程序在矩阵中查找偶数和奇数的频率相关推荐
- 【算法 | 实验18】在字符矩阵中查找给定字符串的所有匹配项
文章目录 题目描述 思路分析 bug记录:"error: '>>' should be '> >' within a nested template argument ...
- Python 列表查找,如何在列表中查找项目或者元素索引【翻译】
Python 列表查找,如何在列表中查找项目或者元素索引 在本文中,你将学习如何在Python中查找列表中包含元素的索引. 有几种方法可以实现这一点,在本文中,你将学习三种不同的方式用于查找列表元素的 ...
- python中偶数怎么表示_Python程序可计算列表中的偶数和奇数
在本文中,我们将学习下面给出的问题陈述的解决方案. 问题陈述-我们得到一个列表,我们需要计算列表中的偶数和奇数. 共有三种方法,如下 - 方法1:使用蛮力方法 示例list1 = [21,3,4,6, ...
- php中判断是否为偶数,在PHP中检查偶数和奇数
给定一个数字,我们必须使用PHP代码检查它是否是奇数的偶数. 偶数是可以被2整除的数字,例如:2.4.6.8.10等,而奇数不能被2整除的数字,例如:3.5.7.9.1等 示例Input: 12 Ou ...
- c++语言偶数分离,在C++的链表中分离偶数和奇数节点
所以,我自学数据结构和算法.在解决一些问题时,我遇到了下面的问题,我必须分离链表的奇偶节点.在C++的链表中分离偶数和奇数节点 以下是问题陈述: 鉴于整数链表,编写一个函数来修改链表,使所有偶数在修改 ...
- python判断奇数和偶数_从Python中的给定列表中提取偶数和奇数
python判断奇数和偶数 In this problem, we are given a list by the user which may be the mixture of even and ...
- kotlin 查找id_Kotlin程序查找给定范围内的素数
kotlin 查找id A prime number is a natural number that is greater than 1 and cannot be formed by multip ...
- kotlin 查找id_Kotlin程序查找立方体区域
kotlin 查找id A cube has 6 square faces, if edges length is side. Then the area of each square is side ...
- kotlin 查找id_Kotlin程序查找平行四边形的区域
kotlin 查找id Formula to find area of Parallelogram: area = base*height 查找平行四边形面积的公式: area = base * he ...
最新文章
- 将类的成员函数作为回调函数(外一篇:友元函数)
- 前端基础之JavaScript_1(一)
- 悬崖边上的舞者,记7.2生产数据库灾难事件
- 小米空调来了,意外的是还一起来了一个马桶盖
- Linux文件基本操作
- python必背语法_python常用语法合集
- 【英语】The Little Prince
- Atitit 发帖机实现(4 )- usbQBM1601 gui操作标准化规范与解决方案attilax总结
- 谷歌浏览器jsonView下载及安装
- Java全栈工程实践
- 苦涩程序员公考上岸之路
- android rom结构_如何将新的ROM刷新到您的Android手机
- 喜马拉雅下载器打赏页面
- 健身装备有哪些推荐?健身运动装备品牌排行榜
- 黑马培训学编程python
- win11右击文件夹假死
- 20220529 pdf 分割合并软件,python tkinter
- 自动化测试需要学习的知识
- 如何用计算机制作动态图,怎样用电脑轻松制作GIF动图图片
- 面对封号潮,跨境收款如何做到不受牵连?