A method of realizing full array of character arrays in Java _java

Source: Internet
Author: User

This article illustrates the method of implementing the whole array of character arrays in Java. Share to everyone for your reference, specific as follows:

Import Org.junit.Test;
public class Allsort {public
 void permutation (char[] buf, int start, int end) {
  if (start = = end) {//When only one word in an array is required When the parent is in full arrangement, just press the array output for
   (int i = 0; I <= end; i++) {
    System.out.print (buf[i]);
   }
   System.out.println ();
  } else {//Multiple letters for
   (int i = start; I <= end; i++) {
    Char temp = buf[start];//Exchange array The first element and subsequent elements
    Buf[start ] = Buf[i];
    Buf[i] = temp;
    Permutation (buf, start + 1, end);/subsequent elements recursively all arranged
    temp = buf[start];//Restore the swapped array
    Buf[start] = buf[i];
    Buf[i] = temp;
   }
 }} @Test public
 void Testpermutation () throws Exception {
  char[] buf = new char[] {' A ', ' B ', ' C '};
  Permutation (buf, 0, 2);
 } 
}

Run the test and output the results:

Abc
Acb
Bac
Bca
Cba
Cab

I hope this article will help you with Java programming.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.