OT: I need help in programming

Other video games, TV shows, movies, general chit-chat...this is an all-purpose off-topic board where you can talk about anything that doesn't have its own dedicated section.

OT: I need help in programming

Postby IlCapitano on Fri Oct 24, 2014 9:44 am

Hi.

I wonder if there's anyone with knowledge about programming in Java and writing code using recursion?

Exercise: Create a Java program that will take a word from a user and shuffle the letters such that it will exchange 2 characters in the word except the first and the last one. To do this exercise use String methods


This is the problem I need solution for.
User avatar
IlCapitano
 
Posts: 68
Joined: Wed Jan 08, 2014 4:49 am

Re: OT: I need help in programming

Postby rise on Wed Oct 29, 2014 1:59 pm

I know this isn't the answer you're looking for, but this example should give you a general idea of a recursion-based program.

http://www.java-samples.com/showtutoria ... rialid=151

class Factorial {
int fact(int n) {
int result;
if ( n ==1) return 1;
result = fact (n-1) * n;
return result;
}
}
class Recursion {
public static void main (String args[]) {
Factorial f =new Factorial();
System.out.println(“Factorial of 3 is “ + f.fact(3));
System.out.println(“Factorial of 3 is “ + f.fact(4));
System.out.println(“Factorial of 3 is “ + f.fact(5));
}
}

In the "Factorial" class, "int fact" is an instance of an integer- you would use a character or a string and instead of calling the instance of the integer "fact", you would call a string "word" and iterate character by character. I don't know the details of your assignment, but this should give you an idea. :wink:
User avatar
rise
But here, at the top of the world, where I raise my hands and I clench my fists...
Contributor
 
Posts: 5266
Joined: Tue Apr 13, 2010 9:52 am
Location: buzz city

Re: OT: I need help in programming

Postby debiler on Wed Oct 29, 2014 6:07 pm

I hope you already know what recursion means. If you don't, there's no point in giving you an example.
Confucius say: "Man go to bed with itchy butt wake up with smelly finger."
User avatar
debiler
 
Posts: 1016
Joined: Wed Nov 13, 2002 8:35 am
Location: Stuttgart, Germany


Return to Off-Topic

Who is online

Users browsing this forum: No registered users and 7 guests