「java打印组合」java打印输出数组
本篇文章给大家谈谈java打印组合,以及java打印输出数组对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
1-10组成不同顺序的组合结果有多少,并打印出来。 JAVA程序实现。
//思路就是利用java的集合类操作。。。达到循环捕捉的效果。。。
//实例如下:
import java.util.*;
public class Combination
{
public static void combination(int n, int position, ListObject choice_list, ListObject current_choice)
{
for(int i = position; i choice_list.size(); i++)
{
current_choice.add((Object) choice_list.get(i));
if(current_choice.size() == n)
{
boolean same = false;
loop: for(int m = 0; m current_choice.size(); m++)
{
for(int k = m + 1; k current_choice.size(); k++)
{
if(current_choice.get(m) == current_choice.get(k))
{
same = true;
break loop;
}
}
}
if(!same)
{
for(int j = 0; j current_choice.size(); j++)
{
System.out.print(current_choice.get(j));
if(j current_choice.size() - 1)
{
System.out.print(",");
}
}
System.out.println();
}
}
else
{
combination(n, 0, choice_list, current_choice);
}
current_choice.remove(current_choice.size() - 1);
}
}
public static void main(String[] args)
{
Object[] arr = "1,2,3,4,5,6,7,8,9,10".split(",");
ListObject str_list = Arrays.asList(arr);
ListObject current_choice = new ArrayListObject();
combination(10, 0, str_list, current_choice);
}
}
java 求组合,打印出8个数字中取3个的组合数
[算法基础]Java实现简单的组合计算——从M个数中取出N个
这个应该可以满足的你的要求
根据你的需求编写的,直接导入到eclipse运行即可
利用Java中字符串打印数组组合
珍藏的排列算法,实现了个java版
public class Test{
static public void swapTwo(final int a[], final int k1, final int k2){
int t=a[k1]; a[k1]=a[k2]; a[k2]=t;
}
static public void permutation(final int a[], final int level, final int n){
if(level==n){
for(int i=0;in;i++) System.out.print(a[i]+" ");
System.out.println();
}else for(int i=level;ia.length;i++){
swapTwo(a, level, i);
permutation(a, level+1, n);
swapTwo(a, i, level);
}
}
public static void main(String[] args) {
int a[]={3,7,9};
permutation(a, 0, 3);
}
}
========
3 7 9
3 9 7
7 3 9
7 9 3
9 7 3
9 3 7
关于java打印组合和java打印输出数组的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。