+ 2

Can you help me to improve this code.

// Created by $Vivek Joshi public class Program{ public static void main(String[] args){ String A="Vivek_Joshi"; for(int i=1;i<=10;i++){ System.out.println(A.substring(0,i)); } for(int i=11;i>=0;i--){ System.out.println(A.substring(0,i)); } } }

24th Jun 2017, 8:44 PM
Vivek Joshi
Vivek Joshi - avatar
3 Answers
+ 3
There is not much to improve. You could take out the brackets from the for loops and delete extra spaces, but keeping the idea the same you can't really make it better.
24th Jun 2017, 8:45 PM
J.G.
J.G. - avatar
+ 1
So instead of using 2 loops. I made it 1 loop. And instead of making it work only for your name. I made it work for any string. https://code.sololearn.com/cQ59527Qi8y4/?ref=app
24th Jun 2017, 9:21 PM
Limitless
Limitless - avatar
0
Hmm it could maybe be improved
24th Jun 2017, 9:08 PM
Limitless
Limitless - avatar