Javamex

Java discussion forum to accompany the Javamex web site.

Hi my name is George.

I want to make a program generate all the possible characters of length 8 using all the characters in charSet

char[] charSet = {0,1,2,3,4,5,6,7,8,9}.
I made that program to understand the algorithm , then I want to make the same with 8 char length.

import java.io.*;

class Brutus {
    public static void main(String args[]) {
        char charSet[] = {'0','1','2','3','4','5','6','7','8','9','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 x = "zzzz";
         for (int i = 0; i < charSet.length; i++) {
             for (int j = 0; j < charSet.length; j++) {
                            for (int k = 0; k < charSet.length; k++) {
                                for (int l = 0; l < charSet.length; l++) {
                String s = charSet[i] + "" + charSet[j]+ "" + charSet[k]+ "" + charSet[l];
                                System.out.println(s);
                                if (x.equals(s)){
                                    System.out.println("the paswd found");
                                }else{
                                    System.out.println("the pswd isn't found");
                                }
             }
         }
 
       
    }
}


But as you see thai is onle 4 characters and I want 8.

I believe that there is another way to make without to make 8 loop with for
.
If anyone have an idea help me.

Views: 29

Reply to This

© 2024   Created by Neil Coffey.   Powered by

Badges  |  Report an Issue  |  Terms of Service