While Loop Structure Javascript Substring Function In Java