关于生成编号的算法,请大家帮助下

jzinfo 2009-03-08 01:50:43
carton箱号,pallet托盘号,集装箱号

一个集装箱中分别装10个pallet,一个pallet托盘中装15个carton箱。
现给定5个集装箱号,分别生成所包含的不重复的pallet托盘号和carton箱号,生成如下的记录到txt文本中:


carton箱号,pallet托盘号,集装箱号
C00000001,P000000001,S000000001
C00000002,P000000001,S000000001
C00000003,P000000001,S000000001
C00000004,P000000001,S000000001
....
C00000015,P000000001,S000000001
C00000016,P000000002,S000000001
....

生成 carton编码和pallet编码容易解决,但匹配成如上的txt 怎么写算法好?
...全文
78 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
ZiSheng 2009-03-08
  • 打赏
  • 举报
回复

public class Test {
public static void main(String [] args){
FileWriter fw=null;
try{
fw=new FileWriter("d:\\dd.txt");
String s;
DecimalFormat dfInt=new DecimalFormat("000000");
for(int i=0;i<11;i++){
for(int j=0;j<5;j++){
for(int k=0;k<3;k++){

s="c"+dfInt.format(k)+",p"+dfInt.format(j)+",s"+dfInt.format(i);
fw.write(s);
fw.write(13);
fw.write(10);
}
}

}
fw.close();
}catch(IOException e){
e.printStackTrace();
}
}

}

格式对齐
ZiSheng 2009-03-08
  • 打赏
  • 举报
回复

public class Test {
public static void main(String [] args){
FileWriter fw=null;
try{
fw=new FileWriter("d:\\dd.txt");
String s;
for(int i=0;i<10;i++){
for(int j=0;j<5;j++){
for(int k=0;k<3;k++){
s="c"+k+",p"+j+",s"+i;
fw.write(s);
fw.write(13);
fw.write(10);
}
}

}
fw.close();
}catch(IOException e){
e.printStackTrace();
}
}

}


rumlee 2009-03-08
  • 打赏
  • 举报
回复
这个太简单了吧,上学的时候老师让打的乘法口诀表差不多啊,一个嵌套循环不就解决了。

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧