
关于split()方法
想编写段代码,功能为:由用户输入一条语句,程序以该语句当中的空格为分割点,分割成为若干段,并分别存入几个变量中。用split()方法写了如下代码,但运行结果不正确,请高手...
想编写段代码,功能为:由用户输入一条语句,程序以该语句当中的空格为分割点,分割成为若干段,并分别存入几个变量中。用split()方法写了如下代码,但运行结果不正确,请高手指点修改
代码如下:
String command=null;
String[] word=new String[3];
Scanner input=new Scanner(System.in);
command=input.next();
word=command.split(" ",3);
for(String w:word){
System.out.println(w);
} 展开
代码如下:
String command=null;
String[] word=new String[3];
Scanner input=new Scanner(System.in);
command=input.next();
word=command.split(" ",3);
for(String w:word){
System.out.println(w);
} 展开
6个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询