import java.util.Scanner; // 添加逗号 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); // 注意 hasNext 和 hasNextLine 的区别 long a = in.nextLong();// 1 2 3 4 5 6 7 8 9 long b = a; int times = 0; // 计算有多少个数字 while(a!=0){ times++; long temp = a%10; a = a/10; } // 从后往前依次填充 String[] res = new String[times]; int cnt = 0; while(b!=0){ cnt++; // System.out.println("-------cnt:"+cnt); long temp = b%10; // 3的倍数,且不是最后一个,才加逗号 res[--times] = (cnt%3 == 0 && times>0) ? ","+(int)temp : (int)temp+""; // 1 2 3 ,4 5 6 ,7 8 9 b = b/10; } // 从前往后遍历 for(int i = 0;i<res.length;i++){ System.out.printf("%s",res[i]); } } }