KT
kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/*
Author: LukArToDo
Created: 07.feb 2018
Bugs: unknown
Description: The code mixes the middle of every word in a text.
*/
import java.util.Random
fun main(LukArToDo: Array<String>){
val s="If you are coming from Java world, you might already have heard about the method overloading in Java. Kotlin, with the help of default parameters and named arguments helps us to reduce the number of overloads that we generally need in Java world."
for(s1 in s.split(" ") ){
val s2=s1.toCharArray()
s2.shuffle()
print(String(s2)+' ')
}
}
fun CharArray.shuffle(){
val rand=Random()
for(i in (if(this[size-1]==','||this[size-1]=='.'||this[size-1]=='!'||this[size-1]=='?'||this[size-1]==':') size-3 else size -2) downTo 2){
val r=rand.nextInt(i)+1
val temp=this[i]
this[i]=this[r]
this[r]=temp
}
}
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run