日期:2014-05-20 浏览次数:20845 次
import java.io.*; import java.util.*; import java.util.regex.*; public class SCJP { public static void main(String args[]){ String input ="10 apples 20 oranges 33 pears"; Scanner s=new Scanner(input).useDelimiter("\\d*"); System.out.print(s.toString()); String str[]=new String[6]; int i=0; while(s.hasNext()){ str[i]=s.next(); System.out.println(str[i++]); } s.close(); } }
public static void main(String args[]) { String input = "10 apples 20 oranges 33 pears"; Scanner s = new Scanner(input).useDelimiter("\\d+"); System.out.println(s.toString()); String str[] = new String[6]; int i = 0; while (s.hasNext()) { str[i] = s.next(); System.out.println(str[i++]); } s.close(); s.close(); }