import java.util.Scanner;
public class Test {
//A20150400001
public static String getNumber(String kind, String year, String month, String num){
if(month.length() == 1){
month = "0" + month;
}
if(num.length() == 1){
num = "0000" + num;
}else if(num.length() == 2){
num = "000" + num;
}else if(num.length() == 3){
num = "00" + num;
}else if(num.length() == 4){
num = "0" + num;
}else if(num.length() > 5){
System.out.println("num is out of range");
}
return kind.concat(year).concat(month).concat(num);
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("input kinds [eg: A]:");
String kind = sc.next();
System.out.println("input year [eg:2015]:");
String year = sc.next();
System.out.println("input month between 1 and 12:");
String month = sc.next();
System.out.println("input num between 1 and 99999:");
String num = sc.next();
System.out.println("The result is :" + getNumber(kind, year, month, num));;
}
}
![](https://video.ask-data.xyz/img.php?b=https://iknow-pic.cdn.bcebos.com/342ac65c103853436b777cc49713b07ecb80889f?x-bce-process=image%2Fresize%2Cm_lfit%2Cw_600%2Ch_800%2Climit_1%2Fquality%2Cq_85%2Fformat%2Cf_auto)
追问这样是可以 但是传入的num值 我是想也让自动增长,例如 4月份第一单到第10单,那num值的是1,2,3,4,5,6,7,8,9,10然后5月份的 第一单到第10单,那num也值的是1,2,3,4,5,6,7,8,9,10。这样的应该怎么写
本回答被网友采纳