import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String str = scanner.next(); //write your code here...... // int n = str.length()/3; // StringBuilder str2 = new StringBuilder(""); // for(int i = 0; i < str.length(); i++) // { // str2.append(str.charAt(str.length() - i -1)); // if( (i+1)%3 == 0) // { // str2.append(","); // } // } // System.out.println(str2.reverse()); StringBuilder str2 = new StringBuilder(str); for(int i = str2.length()-3; i > 0; i-=3) { str2.insert(i,","); } System.out.println(str2); } }
StringBuilder的灵活使用