题解 | #参数解析#
参数解析
https://www.nowcoder.com/practice/668603dc307e4ef4bb07bcd0615ea677
import java.util.*; public class Main { public static void main(String[] args) { Scanner fzhinput = new Scanner(System.in); String zfc = fzhinput.nextLine(); List<String> mllist = new ArrayList<>(); int i = 0; while (i < zfc.length()) { if (zfc.charAt(i) == '"') { // 检查引号 int end = zfc.indexOf('"', i + 1); // 找到下一个引号 if (end != -1) { mllist.add(zfc.substring(i + 1, end)); // 添加去掉引号的字符串 i = end + 1; } else { mllist.add(zfc.substring(i + 1)); break; } } else if (zfc.charAt(i) != ' ') { // 非空格字符开始的参数 int end = i; while (end < zfc.length() && zfc.charAt(end) != ' ') { end++; } mllist.add(zfc.substring(i, end)); // 添加参数 i = end; } else { i++; } } System.out.println(mllist.size()); for (String param : mllist) { System.out.println(param); } } }