anonymous
  • anonymous
Can someone please explain to me this code line by line? I really need help for a test tomorrow. My teacher doesn't really teach at all! public class Recursion { public static void OutPut(int pos, String w, String a){ a = a+ " "; int len= w.length();//length of hello is 5 System.out.println(a+w); if(len>1) { OutPut(pos++, w.substring(pos++,len),a); System.out.println(a+w); } } public static void main(String[] args){ OutPut(0,"hello",""); } }
Computer Science
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
katieb
  • katieb
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
anonymous
  • anonymous
it will display hello ello llo lo o lo llo ello hello
anonymous
  • anonymous
public class Recursion { // defines static method with three inputs // pos = offset into the w string // w = the string to display // a = spaces to make the chars right justified public static void OutPut(int pos, String w, String a){ // This adds an additional space to the a var to // compensate for the substring offset a = a+ " "; // this captures the current length of the w variable // The w variable is updated for each recursive call int len= w.length();//length of hello is 5 //This prints the a spaces followed by the current value of w // This prints the first set of output // hello // ello // llo // lo // o System.out.println(a+w); // If the len of the current substring is greater // than 1 keep calling the recursive function. if(len>1) { // This calls the recurive function OutPut with // the incremented pos value, // the new substring pased on the offset of pos, // and the new set of spaces OutPut(pos++, w.substring(pos++,len),a); // this will end up printing the // lo // llo // ello // hello System.out.println(a+w); } } public static void main(String[] args){ // Call the static method of the Recursion class OutPut // Since it is static you do not need to instantiate the class to call it. OutPut(0,"hello",""); } }
anonymous
  • anonymous
Good luck on your test

Looking for something else?

Not the answer you are looking for? Search for more explanations.

More answers

anonymous
  • anonymous
Thank you soo much!
anonymous
  • anonymous
Oh, and I like your solution better....sorry if my earlier code was unclear...I was working on it at lunch
anonymous
  • anonymous
Oh don't worry about it! Any help is appreciated.

Looking for something else?

Not the answer you are looking for? Search for more explanations.