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 5 of 5

Thread: Build a combination / sequencer

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

    Default Build a combination / sequencer

    Hopefully I put this in the right board topic.

    I'm not sure if I'm using the right wording but I want to build a program that can find a letter combination by doing through a loop trying every combination. It's hard to explain so I basically wrote an example of the output.

    aaaaaa
    aaaaab
    aaaaac
    ...
    zaaaag
    zaaaah
    ...
    zzzzzf
    zzzzzg
    zzzzzh
    ...
    zzzzzx
    zzzzzy
    zzzzzz

    So kind of like the number system, how you have columns (ones, tens, hundreds), each column changes by +1 when the number to the right reaches it's maximum. I want to be able to cycle through the entire alphabet before changing the letter in the next columns by +1, so "A" would become "B".

    I want to be able to use it to find combinations. So their is 6 columns making it possible to find six letter words, like "Hotdog" or "Nature"


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Build a combination / sequencer

    Sounds like a fun project, good luck with it!

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

    Default Re: Build a combination / sequencer

    Andy ideas how to do it? I'm trying "for" loops but it's just easier said than done.

  4. #4
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Build a combination / sequencer

    Quote Originally Posted by traceguy View Post
    I'm trying "for" loops but it's just easier said than done.
    There are many ways to do it. Post what you have so far and explain what problem it has

  5. #5
    Junior Member
    Join Date
    Sep 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Build a combination / sequencer

    I'm gonna work on it for a bit and post my WiP later tonight

    --- Update ---

    Well, I think I finally did it. You may have been right about there being more than one way. I kept starting over with a different strategy until I found one that clicked. I had to use multiple arrays and hard code each column to change when the other one reached the end, which is "z".

    Here is the code
    public class Letters {
    	public static void main (String[] args) {
     
    		// Place counter variables
                    int one = 0;
    		int ten = 0;
    		int hun = 0;
    		int tho = 0;
    		int tentho = 0;
    		int huntho = 0;
     
    		// I"ve decided that I should use 6 arrays rather than 1.
    		// Like the numeric system, there is  master columns. (ones, tens, hundreds)
    		// After I get to the end of the "ones" array, the "tens" array index will +1
    		// and It will repeat.	
    		String[] ones = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
    		String[] tens = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
    		String[] huns = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
    		String[] thos = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
    		String[] tenthos = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
    		String[] hunthos = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
     
     
    for (int i = 0; i < 27; i++)
    {
     if (one == 26) { 
    	i = 0;
    	one = 0;
    	ten++;
    	} 
     if (ten == 26) { 
    	ten = 0;
    	hun++;
    	} 
     if (hun == 26) { 
    	hun = 0;
    	tho++;
    	} 
     if (tho == 26) { 
    	tho = 0;
    	tentho++;
    	} 
     if (tentho == 26) { 
    	tentho = 0;
    	huntho++;
    	} 
    if ( huntho == 27) {
    	i = 27;
    	}	
     
        System.out.print(hunthos[huntho]);
        System.out.print(tenthos[tentho]);
        System.out.print(thos[tho]);
        System.out.print(huns[hun]);
        System.out.print(tens[ten]);
        System.out.print(ones[one]);
     
        one++;
        System.out.println("\n");
     
    } // for loop
     
    } // main	
    } // class

    The code is still running and probably will be for the next few hours until I reach "zzzzzz". Until then I'm not sure if the program will end correctly. That will take a few seconds to fix if not.

Similar Threads

  1. Combination lock
    By Pinares in forum What's Wrong With My Code?
    Replies: 11
    Last Post: February 26th, 2013, 06:56 PM
  2. Combination Lock Class help
    By dx8292 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 4th, 2012, 10:25 AM
  3. how to obtain the combination of ip in String??
    By sxlend in forum Java Networking
    Replies: 2
    Last Post: July 15th, 2012, 01:03 PM
  4. Printing a Combination
    By ranjithfs1 in forum Loops & Control Statements
    Replies: 2
    Last Post: March 6th, 2012, 10:24 AM
  5. A deadly combination
    By grNadpa in forum Object Oriented Programming
    Replies: 5
    Last Post: February 25th, 2012, 06:20 PM