本文共 2240 字,大约阅读时间需要 7 分钟。
kotlin 取整数
Given two integer arrays, we have to concatenate them.
给定两个整数数组,我们必须将它们连接起来。
Example:
例:
Input: arr1 = [10, 20, 30] arr2 = [40, 50] Output: Concatenated array: [10, 20, 30, 40, 50]
package com.includehelp.basicimport java.util.*//Main Function entry Point of Programfun main(args: Array) { //Input Stream val s = Scanner(System.`in`) //Input Array Size print("Enter number of elements in the array1: ") var size = s.nextInt() //Create Integer array of Given size val intArray1 = IntArray(size) //Input array elements println("Enter Arrays Elements:") for (i in intArray1.indices) { print("intArray1[$i] : ") intArray1[i] = s.nextInt() } //Input Array Size print("Enter number of elements in the array2: ") size = s.nextInt() //Create Integer array of Given size val intArray2 = IntArray(size) //Input array elements println("Enter Arrays Elements:") for (i in intArray2.indices) { print("intArray2[$i] : ") intArray2[i] = s.nextInt() } //Print Array1 Elements println("Array1 : ${intArray1.contentToString()}") //Print Array2 Elements println("Array2 : ${intArray2.contentToString()}") var concatArray = intArray1+intArray2 //Print concatArray Elements and its Size println("concatArray Elements : ${concatArray.contentToString()}") println("concatArray Size : ${concatArray.size}")}
Output
输出量
Run 1:-----Enter number of elements in the array1: 5Enter Arrays Elements:intArray1[0] : 3intArray1[1] : 4intArray1[2] : 5intArray1[3] : 6intArray1[4] : 798Enter number of elements in the array2: 3Enter Arrays Elements:intArray2[0] : 2intArray2[1] : 1intArray2[2] : 9Array1 : [3, 4, 5, 6, 798]Array2 : [2, 1, 9]concatArray Elements : [3, 4, 5, 6, 798, 2, 1, 9]concatArray Size : 8--------Run 2:----Enter number of elements in the array1: 2Enter Arrays Elements:intArray1[0] : 6intArray1[1] : 5Enter number of elements in the array2: 3Enter Arrays Elements:intArray2[0] : 5intArray2[1] : 3intArray2[2] : 2Array1 : [6, 5]Array2 : [5, 3, 2]concatArray Elements : [6, 5, 5, 3, 2]concatArray Size : 5
翻译自:
kotlin 取整数
转载地址:http://ezozd.baihongyu.com/