题解 | #参数解析#
参数解析
https://www.nowcoder.com/practice/668603dc307e4ef4bb07bcd0615ea677
import java.util.*; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); // 注意 hasNext 和 hasNextLine 的区别 while (in.hasNext()) { // 注意 while 处理多个 case String b = in.nextLine()+" "; ArrayList<String> list = new ArrayList(); for(int i = 1 ,j = 0 ;i < b.length() ; i ++){ char c = b.charAt(i); if(c == ' '){ String res = b.substring(j,i); list.add(res); j= i+1 ; }else if (c == '"'){ j= ++i; char d = b.charAt(i); while (d!='"'){ i++; d= b.charAt(i); } String res = b.substring(j,i); j = ++i+1; list.add(res); } } System.out.println( list.size()); for(String str : list){ System.out.println( str); } } } }