java - How to make a word triangle with spaces where next characters will appear -


i'm having trouble creating spaces before string. want this

         na    ana   nana  anana banana 

here code now

    public static void main(string[] args){     string str = "banana";     for(int y = str.length() - 1; y >=  0 ; y--) {         system.out.println(str.substring(y));     } }  na ana nana anana banana 

i need characters shifted right many characters string.

system.out.format("%"+str.length()+"s%n", str.substring(y)); 

definitely better if store length first, suggested in comment

string str = "banana"; string formatstring = "%"+str.length()+"s%n"; for(int y = str.length() - 1; y >=  0 ; y--) {     system.out.format(formatstring , str.substring(y)); } 

Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

python - pip wont install .WHL files -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -