Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

liquifiedkronic Group Title

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",""); } }

  • 2 years ago
  • 2 years ago

  • This Question is Closed
  1. liquifiedkronic Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    it will display hello ello llo lo o lo llo ello hello

    • 2 years ago
  2. ecdown Group Title
    Best Response
    You've already chosen the best response.
    Medals 5

    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",""); } }

    • 2 years ago
  3. ecdown Group Title
    Best Response
    You've already chosen the best response.
    Medals 5

    Good luck on your test

    • 2 years ago
  4. liquifiedkronic Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    Thank you soo much!

    • 2 years ago
  5. ecdown Group Title
    Best Response
    You've already chosen the best response.
    Medals 5

    Oh, and I like your solution better....sorry if my earlier code was unclear...I was working on it at lunch

    • 2 years ago
  6. liquifiedkronic Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    Oh don't worry about it! Any help is appreciated.

    • 2 years ago
    • Attachments:

See more questions >>>

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.