请教数字拆分程序编写! 将数字: 0, 1, 2,3,4,5,6,7,8,9 这十个数字任意5个拆分成两组, 并打印出每种拆分结果!谢谢!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 /** * project_name: Test * package_name: netsource * package_declaration: package netsource; * filename: DivNumber.java * author: yuhaiming * date: 2007-11-9 */package netsource;import java.math.*;public class DivNumber { /** * 主处理函数 */ public static void disposal(){ int[][] answer = new int[252][5]; int[] a = new int[5]; int answersize = 0; while(true){ int acount=0; //生成数组序列 while(true){ //得到一个0-9的随机数 int randomvalue = (int)(Math.random()*10); //System.out.println(randomvalue); if(checkRandomValue(a,randomvalue)){ a[acount++]=randomvalue; //System.out.println("检验通过"); } if(acount>=5)break; } //打印该数组 printinfo(a); //检验生成的数组,如果满足则拷贝 if(true){ System.out.println("长度:"+answersize); //printAnswer(answer,answersize-1); System.out.println("检验通过,开始拷贝"); for(int i=0;i<5;i++){ answer[answersize][i]=a[i]; } answersize++; //System.out.println("***********************************"); printAnswer(answer,answersize); } if(answersize>=252)break; } } /** * 打印数组 * @param inf */ public static void printinfo(int[] inf){ for(int i=0;i<inf.length;i++){ System.out.print(inf[i]+" "); } System.out.println(); } /** * 检查已分组是否重复 * @param curanswer * @param checkvalue * @return */ public static boolean checkAnswerArray(int[][] curanswer,int[] checkvalue,int answersize){ //对已有数组集进行遍历处理,检查出是否有相同的分组 for(int i=0;i<answersize;i++){ //重复元素统计 int count = 0; //统计总共重复元素个数 for(int j=0;j<checkvalue.length;j++){ if(checkRandomValue(curanswer[i],checkvalue[j])) count++; } //计数器为5说明,该数组和原来某条数据一致,返回失败标志 if(count==5)return false; } return true; } /** * 检查新生成的数是否在已赋值的数组中,防止重复赋值 * @param result * @param checkvalue * @return */ public static boolean checkRandomValue(int[] result,int checkvalue){ for(int i=0;i<result.length;i++){ if(checkvalue==result[i])return false; } return true; } /** * 打印最终结果集 */ public static void printAnswer(int[][] answerPrint,int answersize){ System.out.println("总共有"+answersize+"种分组:"); for(int i=0;i<answersize;i++){ for(int j=0;j<5;j++){ System.out.print(answerPrint[i][j]+" "); } System.out.println(""); System.out.println("-------------"); } } /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub disposal(); //printAnswer(); }} java运行时处理文件路径的问题~~ 自己写个名字为String的类为什么不行 关于使用jdbc读取sql server 的long text遇到的问题,棘手,请教大侠们 请教java.lang.NoSuchMethodError: main问题 jsp:param用法 runtime.getruntime().exec(command)的一个问题? 综合问题~急~~ (100分求源码或设计思路,分不够可在加!)实现数组排序问题? 文件上传,特例!! java小白 java方法的参数问题 请教关于POI的问题,跪求,感激!
/**
* project_name: Test
* package_name: netsource
* package_declaration: package netsource;
* filename: DivNumber.java
* author: yuhaiming
* date: 2007-11-9
*/
package netsource;
import java.math.*;
public class DivNumber {
/**
* 主处理函数
*/
public static void disposal(){
int[][] answer = new int[252][5];
int[] a = new int[5];
int answersize = 0;
while(true){
int acount=0;
//生成数组序列
while(true){
//得到一个0-9的随机数
int randomvalue = (int)(Math.random()*10);
//System.out.println(randomvalue);
if(checkRandomValue(a,randomvalue)){
a[acount++]=randomvalue;
//System.out.println("检验通过");
}
if(acount>=5)break;
}
//打印该数组
printinfo(a);
//检验生成的数组,如果满足则拷贝
if(true){
System.out.println("长度:"+answersize);
//printAnswer(answer,answersize-1);
System.out.println("检验通过,开始拷贝");
for(int i=0;i<5;i++){
answer[answersize][i]=a[i];
}
answersize++;
//System.out.println("***********************************");
printAnswer(answer,answersize);
}
if(answersize>=252)break;
}
}
/**
* 打印数组
* @param inf
*/
public static void printinfo(int[] inf){
for(int i=0;i<inf.length;i++){
System.out.print(inf[i]+" ");
}
System.out.println();
}
/**
* 检查已分组是否重复
* @param curanswer
* @param checkvalue
* @return
*/
public static boolean checkAnswerArray(int[][] curanswer,int[] checkvalue,int answersize){
//对已有数组集进行遍历处理,检查出是否有相同的分组
for(int i=0;i<answersize;i++){
//重复元素统计
int count = 0;
//统计总共重复元素个数
for(int j=0;j<checkvalue.length;j++){
if(checkRandomValue(curanswer[i],checkvalue[j]))
count++;
}
//计数器为5说明,该数组和原来某条数据一致,返回失败标志
if(count==5)return false;
}
return true;
}
/**
* 检查新生成的数是否在已赋值的数组中,防止重复赋值
* @param result
* @param checkvalue
* @return
*/
public static boolean checkRandomValue(int[] result,int checkvalue){
for(int i=0;i<result.length;i++){
if(checkvalue==result[i])return false;
}
return true;
}
/**
* 打印最终结果集
*/
public static void printAnswer(int[][] answerPrint,int answersize){
System.out.println("总共有"+answersize+"种分组:");
for(int i=0;i<answersize;i++){
for(int j=0;j<5;j++){
System.out.print(answerPrint[i][j]+" ");
}
System.out.println("");
System.out.println("-------------");
}
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
disposal();
//printAnswer();
}}