我使用数组在Java中创建了一个控制台程序,我需要以最多100次的格式在一行中输入我的所有代码。将代码添加到我的代码中
car_make_name:car_model_name:car_model_tax:car_model_price
这两个字符串和两个int变量,我有代码写出来,但我不知道如何使用.split输入正确的信息到相应的变量。
这是我的代码:
public class Main {
public static void main (String[] args)
{
//Arrays declared
String[] cars = new String[20];
String[] car_model_name = new String[20];
int[] car_model_tax = new int[20];
String[] car_make_name = new String[20];
int[] car_model_price = new int[20];
Scanner scan = new Scanner (System.in);
//Loop??
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
if (line.equals("quit", "QUIT", "Quit")) {
}
}
break;
for (int x = 0; x < cars.length; x++){
System.out.println("Enter details, separating each with a ':' ");
cars[x] = System.console().readLine();
}
}
}
你的问题只是“如何使用拆分”,或者你问如何从相同的字符串(字符串和整数)提取不同的数据类型? – synchronizer