Ace school

with brainly

  • Get help from millions of students
  • Learn from experts with step-by-step explanations
  • Level-up by helping others

A community for students.

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
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
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.

Get this expert

answer on brainly

SEE EXPERT ANSWER

Get your free account and access expert answers to this and thousands of other questions

it will display hello ello llo lo o lo llo ello hello
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",""); } }
Good luck on your test

Not the answer you are looking for?

Search for more explanations.

Ask your own question

Other answers:

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

Not the answer you are looking for?

Search for more explanations.

Ask your own question