RashedBQ

Array-old +Array-new

Jul 6th, 2021 (edited)
73
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var arr =Array<Int>(20){0}
  2.  
  3.     println("Enter any number")
  4.     for (i in 0 until  arr.size)
  5.     {
  6.         arr[i]= readLine()!!.toInt()
  7.     }
  8.     var c =0
  9.     for (i in 0 until  arr.size)
  10.     {
  11.         if (arr[i] %2 ==1) c++
  12.  
  13.     }
  14.  
  15.     var newarr =Array<Int>(c){0}
  16.     var k=0
  17.     for (i in 0 until arr.size)
  18.     {
  19.         if (arr[i] %2 ==1 ) {
  20.             newarr[k]=arr[i]
  21.             k++
  22.         }
  23.  
  24.     }
  25.     println("---------odd numbers---------")
  26.  
  27.     for (i in  newarr.size -1 downTo 0)
  28.     {
  29.         println(newarr[i])
  30.     }
  31.     println("---------even numbers---------")
  32.  
  33.     for (i in  arr.size -1 downTo 0)
  34.     {
  35.         if (arr[i] %2 ==0 ) {
  36.             println(arr[i])
  37.         }
  38.     }
RAW Paste Data Copied