分析
1.将字符串拆分到数组
2.使用循环进行遍历 从后往前进行遍历
3.% 3==0 并且 i !=0 拼接
4.需要正着获取数据
public static void main(String[] args) {Scanner input = new Scanner(System.in);System.out.println("请输入银行卡的余额:");String money=input.next();//拆分到数组中String [] arrays = new String[money.length()];//将字符添加到数组中for (int i=0;i<arrays.length;i++){arrays[i]=money.charAt(i)+"";}//定义一个字符串进行拼接String word="";//使用循环遍历数组 倒着遍历for (int i=arrays.length-1;i>=0;i--){if (i!=0 && i%3 ==0){word+=arrays[arrays.length-1-i]+",";}elseword+=arrays[arrays.length-1-i];//word+=(i!=0 && i%3 ==0)?arrays[arrays.length-1-i]+"," :arrays[arrays.length-1-i];}System.out.println(word);
}