Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Anagram Program

  1. #1
    Junior Member
    Join Date
    Jul 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Anagram Program

    hello everyone, i am a beginner in java programming and i usually look in the internet for the solutions of my homeworks in java for my subject and i encountered this code and i really don't understand how it works so please, can anybody can explain it to me please.... i really need your help now!!! Thanks in advance!!!
    public class Anagram {
    	public void anag(String s1, String s2)	{
    		if(s1.length() == 0)	{
    			System.out.println(s2);
    		}
    		for(int i = 0; i < s1.length(); i++)	{
    			anag(s1.substring(0, i) + s1.substring(i+1, s1.length()), s1.charAt(i) + s2);
    		}
    	}
    	public static void main(String[] args)	{
    		Anagram ana = new Anagram();
    		ana.anag("farm", "");
    	}
     
    }


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Anagram Program

    i usually look in the internet for the solutions of my homeworks
    So you don't actually write any of your own code? That's sad, and means you're not learning much.
    can anybody can explain it to me please
    Tell us first what you think the code does and ask for correction/help understanding the parts you've gotten wrong.

  3. #3
    Member
    Join Date
    Jul 2013
    Posts
    219
    Thanks
    0
    Thanked 18 Times in 17 Posts

    Default Re: Anagram Program

    Hi,
    If you want to understand the code just trace the program statement by statement from main() using a pen and paper.
    You shall know what is happening.

    Syed.

Similar Threads

  1. Program goes into infinite compilation. University project - Library Program.
    By clarky2006 in forum What's Wrong With My Code?
    Replies: 35
    Last Post: November 10th, 2012, 03:56 PM
  2. Replies: 1
    Last Post: July 8th, 2012, 10:23 AM
  3. Anagram program help?
    By EsKiMoMoNKeY in forum Java Theory & Questions
    Replies: 1
    Last Post: April 10th, 2012, 06:28 AM
  4. anagram program wont compile please help
    By Rusak in forum What's Wrong With My Code?
    Replies: 5
    Last Post: March 26th, 2011, 06:23 PM
  5. Anagram program wont compile
    By Rusak in forum Member Introductions
    Replies: 0
    Last Post: March 25th, 2011, 02:38 PM

Tags for this Thread