daily pastebin goal
1%
SHARE
TWEET

Untitled

a guest Jan 11th, 2012 635 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. fun main(args : Array<String>) {
  2.   val data = "word asdasdasduIUASHDasd     asdweqrasasdasdasdaDASDASdasdASDASD    "
  3.   System.out?.println("Input data: ${data}")
  4.   var longestWord = -1;
  5.   var longestWordStart = -1;
  6.   var lastWordStart = 0;
  7.   for(i in 0..data.length)
  8.   {
  9.     if ((i == data.length) || (!Character.isLetter(data.get(i))))
  10.     {
  11.       var wordLength = i - lastWordStart;
  12.       if ((wordLength > 0) && (longestWord < wordLength))
  13.       {
  14.         longestWord = wordLength;
  15.         longestWordStart = lastWordStart;
  16.       }
  17.       lastWordStart = i + 1;
  18.     }
  19.   }
  20.  
  21.   if (longestWord == -1)
  22.   {
  23.     System.out?.println("Nothing found")
  24.   }
  25.   else
  26.   {
  27.     System.out?.println("Longest word: ${ data.substring(longestWordStart, longestWordStart+longestWord) }")
  28.   }
  29. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top