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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

kotlin键值对数组_Kotlin程序以升序对数组进行排序

發布時間:2023/12/1 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 kotlin键值对数组_Kotlin程序以升序对数组进行排序 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

kotlin鍵值對數組

Given an array, we have to sort its elements in ascending order.

給定一個數組,我們必須按升序對其元素進行排序。

Example:

例:

Input:arr = [10, 20, 5, 2, 30]Output:sorted array (Ascending Order): [2, 5, 10, 20, 30]

在Kotlin中以升序對數組進行排序的程序 (Program to sort an array in ascending order in Kotlin)

package com.includehelp.basicimport java.util.*//Main Function entry Point of Program fun main(args: Array<String>) {//Input Streamval s = Scanner(System.`in`)//Input Array Sizeprint("Enter number of elements in the array: ")val size = s.nextInt()//Create Integer array of Given sizeval intArray = IntArray(size)//Input array elementsprintln("Enter Arrays Elements:")for (i in intArray.indices) {print("intArray[$i] : ")intArray[i] = s.nextInt()}//to Perform Ascending Order Sorting on integer Arrayvar temp:Intfor (i in intArray.indices) {for (j in i + 1 until intArray.size) {if (intArray[i] > intArray[j]) {temp = intArray[i]intArray[i] = intArray[j]intArray[j] = temp}}}//Alternatively we can also use sort() method of Arrays //Class in kotlin to sort in Ascending Order//intArray.sort()print("Ascending Order: ")for (item in intArray) {print("$item ")} }

Output

輸出量

Enter number of elements in the array: 6 Enter Arrays Elements: intArray[0] : 5 intArray[1] : 23 intArray[2] : 1 intArray[3] : 0 intArray[4] : 9 intArray[5] : 76 Ascending Order: 0 1 5 9 23 76 ---------------- Enter number of elements in the array: 8 Enter Arrays Elements: intArray[0] : 45 intArray[1] : 3 intArray[2] : 89 intArray[3] : -8 intArray[4] : -45 intArray[5] : 0 intArray[6] : 432 intArray[7] : 6 Ascending Order: -45 -8 0 3 6 45 89 432

翻譯自: https://www.includehelp.com/kotlin/sort-an-array-in-ascending-order.aspx

kotlin鍵值對數組

總結

以上是生活随笔為你收集整理的kotlin键值对数组_Kotlin程序以升序对数组进行排序的全部內容,希望文章能夠幫你解決所遇到的問題。

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