+ 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)); } } }
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.
+ 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
0
Hmm it could maybe be improved