Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6635977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:07:33+00:00 2026-05-25T23:07:33+00:00

This is what I have so far. package testproject; public class Combinations{ public Combinations(){

  • 0

This is what I have so far.

package testproject;

public class Combinations{

      public Combinations(){

        String str_arr[]={"a","b","c"};
        GenCombinations(str_arr);
      }




      public void GenCombinations(String[] str_arr){

        System.out.println("Generating All possible Combinations for  the following "+str_arr.length+" strings.");        

        for(int i=0;i<str_arr.length;i++)
         {
            System.out.print(str_arr[i]+" ");
         }
        System.out.println("\n------------------------------------------");

        /*COMBINATIONS OF LENGTH ONE*/
        for(int i=0;i<str_arr.length;i++)
            System.out.println(str_arr[i]);        

        /*COMBINATIONS OF LENGTH TWO*/
        for(int i=0;i<str_arr.length;i++)
         {
           for(int j=0;j<str_arr.length;j++)
             {
                System.out.println(str_arr[i]+""+str_arr[j]);                   
             }
         } 

        /*COMBINATIONS OF LENGTH THREE*/
        for(int i=0;i<str_arr.length;i++)
         {
          for(int j=0;j<str_arr.length;j++)
           {
            for(int k=0;k<str_arr.length;k++)
             {  
                System.out.println(str_arr[i]+""+str_arr[j]+""+str_arr[k]);                      
             }
           }
         }
      } 


      public static void main(String[] args){

        new Combinations();
      }
    }

Any suggestions will be appreciated..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T23:07:34+00:00Added an answer on May 25, 2026 at 11:07 pm

    If you want to generate all possible substrings of length k from a given alphabet, then what you’re doing is pretty much optimal.

    If you want to generate all possible combinations of length k from a given set (or alphabet) with n elements (C(n, k)), then a classical solution is to use Rosen’s algorithm.

    For example, given a 5-letter alphabet, if you want to take 3 combinations at a time, the gist of it is to count like so:

    012
    013
    014
    023
    024
    034
    123
    .
    .
    .
    

    Here’s my implementation of a RosenIterator in Java.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am Currently learning Generics I have this Generic class here package generics.lesson; public
Thanks to everyone out there helping newbies like me. So far I have this:
This is what I have so far - my dropbox public URL creation script
I have this so far but the Column 'name' is ambiguous, so I want
I have this so far but I don't know how to write over the
I have this so far: http://jsfiddle.net/u5vhS/54/ . What I want to be able to
So far i have this: mov ah,02h mov cl,11001100001111011101000b ;6,692,584 in dec mov dl,0
I'm using the javascript module pattern, and have this so far: var APP; if(APP
This is what I have so far: [my1@graf home]$ curl -# -o f1.flv 'http://osr.com/f1.flv'
This is what I have as far as code, it is in the first

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.