我定义了 3 个方法,其中有 String[] 作为参数。我想从另一个函数设置这些,使用一些字符串,并打印每个字符串。
当我尝试从另一个函数(start() 函数)调用这些方法时,设置 String[] 参数的值 Eclipse 说:
类型不匹配:无法从 String 转换为 String[]
public class logistics2 {
private static String plane;
private static String truck;
private static String airport[];
private static String loc[];
private static String city[];
private static String pack[];
public static void at_obj_place(String object, String[] place) {
object = truck;
object = plane;
place = loc;
place = city;
place = airport;
return;
}
public static void in_pk_vehicle(String[] Pack, String vehicle) {
Pack = pack;
vehicle = truck;
vehicle = plane;
return;
}
public static void in_city(String[] place, String[] City ) {
place = loc;
City = city;
return;
}
public static void start() {
// HERE I RECEIVE THE ERROR MESSAGE
in_city(airport = "cdg", city = "paris");
in_city(airport = "lhr", city = "london");
in_city(loc = "north", city = "paris");
in_city(loc = "south",city = "paris");
at_obj_place(plane = "plane", airport = "lhr");
at_obj_place(truck = "truck", airport = "cdg");
at_obj_place(pack1 = "p1", airport = "lhr");
at_obj_place(pack2 = "p2", airport = "lhr");
for(int i = 0; i < airport[].length(); ) {
System.out.println(airport + " " + city);
}
return;
我想根据我在 String[] 中插入的值的计数来打印使用 for 条件设置的每个值
一只甜甜圈
相关分类