又偷懒了。。JAVA里有format类,直接拿来用,省好多功夫
import java.text.DecimalFormat;
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
sc.nextLine();
while (n != 0)
{
double sum = 0;
while (n-- > 0)
{
String s = sc.nextLine();
double d = Double.parseDouble(s.substring(1)
.replaceAll(",", ""));
sum += d;
}
System.out.println("$"+ new DecimalFormat("#,##0.00").format(sum));
n = sc.nextInt();
sc.nextLine();
}
}
}