Main Site | Forum | Rules | Downloads | Wiki | Features | Podcast

NLSC Forum

Switch to full style
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.
Post a reply

OT: I need help in programming

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.

Re: OT: I need help in programming

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:

Re: OT: I need help in programming

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.
Post a reply