package step1;
import java.util.List;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.StringTokenizer;
public class SplitDemo{
public static List<String> splitPartition(String str){
ArrayList<String> list = new ArrayList<String>();
String[] sp = str.split("\\.");
int i = 0;
for(String s:sp){
list.add(i++,s);
}
return list;
}
public static List<Double> tokenPartition(String str){
ArrayList<Double> listTemp = new ArrayList<Double>();
String []s1 = str.split(" ");
for(String s2:s1){
try{
Double d = Double.parseDouble(s2);
listTemp.add(d);
}catch (Exception e){
continue;
}
}
return listTemp;
}
}
package step1;
import java.util.List;
import java.util.ArrayList;
import java.util.Scanner;
public class Test{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
SplitDemo demo=new SplitDemo();
String str1=sc.nextLine();
String str2=sc.nextLine();
List<String> list1=demo.splitPartition(str1);
for(String s:list1){
System.out.println(s);
}
System.out.println();
List<Double> list2=demo.tokenPartition(str2);
double sum=0;
for (int i = 0; i < list2.size(); i++) {
System.out.println(list2.get(i));
sum=sum+list2.get(i);
}
System.out.printf("sum=%.4f\n",sum);
}
}