输入一行字符串,可以有空格,输出参数个数,分解后的参数,每个参数都独占一行
参数解析
http://www.nowcoder.com/questionTerminal/668603dc307e4ef4bb07bcd0615ea677
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String nextLine = scanner.nextLine();
StringBuilder stringBuilder = new StringBuilder();
ArrayList<String> arrayList = new ArrayList();
boolean flag = false;
for (int i = 0; i < nextLine.length(); i++) {
char c = nextLine.charAt(i);
if (String.valueOf(c).equals("\"")) {
flag = flag ? false : true;
continue;
}
if (String.valueOf(c).equals(" ") && !flag) {
arrayList.add(stringBuilder.toString());
stringBuilder = new StringBuilder();
} else {
stringBuilder.append(c);
}
}
arrayList.add(stringBuilder.toString());
System.out.println(arrayList.size());
for (String s : arrayList) {
System.out.println(s);
}
}}
查看14道真题和解析
阿里云工作强度 673人发布