java - Take a word and print it out in the shape of a triangle as shown below - Parameters and methods -


thanks taking time check out question. have write code in dr. java takes in word , prints out in specific pattern. here examples:

input: fishy output: f          fifi          fisfisfis          fishfishfishfish          fishyfishyfishyfishyfishy 

basically, i'm adding character previous 1 , printing out many number of times.

here attempt @ solution:

string wordcopy = word;     int size = wordcopy.length();    (int i=1; i<=size; i+=1)   {     (int j=0; j<i; j++)     {         system.out.print(word.substring(0,j+1));     }     system.out.println("");   }} 

i have set parameters that's fine. thing seem missing method prints out it's supposed to. can please me problem , how can go here? thanks!

replace word.substring(0,j+1) word.substring(0,i):

    string wordcopy = word;     int size = wordcopy.length();     (int = 1; <= size; += 1) {         (int j = 0; j < i; j++) {             system.out.print(word.substring(0, i));         }         system.out.println("");     } 

there cleanup things can do. instance, code yields same result:

    (int = 1; <= word.length(); i++) {         (int j = 0; j < i; j++) {             system.out.print(word.substring(0, i));         }         system.out.println("");     } 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -