kotlin 查找id

有哪些因素? (What are the factors?)

Factors of a number are those numbers you multiply them to get the number. For example: If a number is 6, it's factors will be 2 and 3, if we multiply them, then it will be the number again: 2x3=6.

数字的因子是那些数字乘以它们得到的数字。 例如:如果一个数字为6,则因数将为2和3,如果我们将它们相乘,则它将再次为该数字:2x3 = 6。

Given a number, we have to find its all factors.

给定一个数字,我们必须找到其所有因素。

Example:

例:

    Input:
    number = 6

    Output:
    2, 3

查找Kotlin数量因素的程序 (Program to find factors of a number in Kotlin)

package com.includehelp.basic

import java.util.*

//Main Function entry Point of Program
fun main(args: Array<String>) {
    //Input Stream
    val scanner = Scanner(System.`in`)

    //input integer number
    println("Enter Number  : ")
    val number: Int = scanner.nextInt()

    //Declare Mutable List to hold factors
    val list: MutableList<Int> = ArrayList()

    //Find the factor of using loop
    for(i in 1..number){
        if(number%i==0){
            list.add(i)
        }
    }

    //print factors
    println("Factors of $number are $list")
}

Output

输出量

Run 1:
Enter Number  :
240
Factors of 240 are [1, 2, 3, 4, 5, 6, 8, 10, 12, 15, 16, 20, 24, 30, 40, 48, 60, 80, 120, 240]

-------
Run 2:
Enter Number  :
500
Factors of 500 are [1, 2, 4, 5, 10, 20, 25, 50, 100, 125, 250, 500]
-------
Run 3:
Enter Number  :
179
Factors of 179 are [1, 179]


翻译自: https://www.includehelp.com/kotlin/find-factors-of-a-number.aspx

kotlin 查找id

Logo

开源鸿蒙跨平台开发社区汇聚开发者与厂商,共建“一次开发,多端部署”的开源生态,致力于降低跨端开发门槛,推动万物智联创新。

更多推荐