当前位置:   article > 正文

java 数组_java基础类型数组 统一接收

java基础类型数组 统一接收

在这里插入图片描述

三: 全局数组

        全局数组初始化, int 类型数组初始化为 0,boolean 数组初始化为 false

        举例:全排列

import java.util.Hashtable;

public class Quanpailie {
	private static int n;
	private static int maxn = 11;
	static int p[] = new int[maxn]; //初始化 maxn 个0
	static boolean hashTable[] = new boolean[maxn]; //初始化 maxn 个 false
	public static void generateP(int index) {
		if (index == n+1) {
			for (int i = 1; i <= n; i++) {
				System.out.print(p[i]+" ");
			}
			System.out.println();
			return;
		}
		
		for (int x = 1; x <= n; x++) {
			if (hashTable[x] == false) {
				hashTable[x] = true;
				p[index] = x;
				generateP(index+1);
				hashTable[x] = false;
			}
		}
	}
	public static void main(String[] args) {
		System.out.println(hashTable.length);
		for (int i = 0; i < maxn; i++) {
			System.out.println(p[i]); 
		}
		n = 3;
		generateP(1);
	}
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/article/detail/44397
推荐阅读
相关标签
  

闽ICP备14008679号