Python:
a=['阿莫西林克拉维酸钾分散片', '*清肺消炎丸', '*小儿咳喘灵口服液', '阿法骨化醇软胶囊']
b=['5片/次', '5粒/次', '2片/次', '0.25ug/次']
c=['08:00,12:00,18:00,10:46,10:58',
'16:04',
'08:00,11:43,11:39,11:20,11:26',
'08:00,12:00,16:00,16:01,16:21,16:10']
len_a=len(a)
len_b=len(b)
len_c=len(c)
if len_a !=len_b or len_a != len_c:
print("药品、药品规格、时间个数不一致")
all_list=[]
for i in range(len_a):
#以| 分隔
all_list.append(a[i]+"|"+ b[i] +"|" +c[i])
print(all_list)
Java:
import java.util.Arrays;
public class demoList {
public static void main(String[] args) throws Exception {
String a[] = { "阿莫西林克拉维酸钾分散片", "*清肺消炎丸", "*小儿咳喘灵口服液", "阿法骨化醇软胶囊" };
String b[] = { "5片/次", "5粒/次", "2片/次", "0.25ug/次" };
String c[] = { "08:00,12:00,18:00,10:46,10:58", "16:04", "08:00,11:43,11:39,11:20,11:26",
"08:00,12:00,16:00,16:01,16:21,16:10" };
int aLength = a.length;
int bLength = b.length;
int cLength = c.length;
//三个数组元素不一致则抛异常
if (aLength != bLength || aLength != cLength) {
throw new Exception("药品、药品规格、时间个数不一致");
}
String result[] = new String[aLength];
//每个元素拼接格式
String formatStr = "'%s'-'%s'-'%s'";
//拼接三个数组元素
for(int i = 0 ; i<aLength ; i++) {
result[i] = String.format(formatStr, a[i], b[i], c[i]);
}
//打印成一行
System.out.println(Arrays.toString(result));
System.out.println("==========================================================");
//每个元素分开打印
for (String string : result) {
System.out.println(string);
}
}
}