关于Java的一道小试题!
3个回答
展开全部
public static void main(String args[]) {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入字符串:");
String str = scanner.nextLine();
System.out.println("请输入分隔符");
Character ch = scanner.next().charAt(0);
String[] strs = str.split(ch.toString());
for(int i = 0 ; i < strs.length ; i++){
System.out.println("数组第" + (i+1) + "个元素是:" + strs[i]);
}
}
Scanner scanner = new Scanner(System.in);
System.out.println("请输入字符串:");
String str = scanner.nextLine();
System.out.println("请输入分隔符");
Character ch = scanner.next().charAt(0);
String[] strs = str.split(ch.toString());
for(int i = 0 ; i < strs.length ; i++){
System.out.println("数组第" + (i+1) + "个元素是:" + strs[i]);
}
}
展开全部
import java.util.*;
public class splitString {
public static void main(String[] args) {
String s1;
String s2;
Scanner scan=new Scanner(System.in);
System.out.print("Please input the String!");
s1=scan.nextLine();
System.out.print("Please input the splitString");
s2=scan.next();
String zu[]=s1.split(s2);
for(int i=0;i<zu.length;i++){
System.out.println(zu[i]);
}
}
}
public class splitString {
public static void main(String[] args) {
String s1;
String s2;
Scanner scan=new Scanner(System.in);
System.out.print("Please input the String!");
s1=scan.nextLine();
System.out.print("Please input the splitString");
s2=scan.next();
String zu[]=s1.split(s2);
for(int i=0;i<zu.length;i++){
System.out.println(zu[i]);
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
StringTokenizer tstr = StringTokenizer(str, delim)
while (st.hasMoreTokens()) {
System.out.println(st.nextToken());
}
str - 要解析的字符串。
delim - 分隔符
while (st.hasMoreTokens()) {
System.out.println(st.nextToken());
}
str - 要解析的字符串。
delim - 分隔符
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询