如何使用子字符串java的单独数字?

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (1)
  • 关注 (0)
  • 查看 (43)

想用Java创建一个从用户那里获取号码的程序_输入并使之成为货币格式,以下是我使用的代码:

package Seperator_checker;

import java.util.Scanner;

public class Seperator {

    public static void main(String[] args) {
        Scanner number=new Scanner(System.in);
        System.out.print("Please Enter Your Number: ");
        String user_number=number.next();
        if(user_number.length()> 3) {
            user_number=user_number.substring(0,user_number.length()-3) + "," + user_number.substring(0,1);
            System.out.println("________________________________________");
            System.out.println("Your Currency Number Is: "+ user_number);
        }

    }

}
提问于
用户回答回答于

这样试试:

Convert String to Char List
goto end of List
counter = 0
while havent reached beginning of list
    counter += 1
    if counter == 3
        counter = 0
        insert ',' into List
        //maybe go back one here too depending on implementation of 
        //insert and which is the current element after inserting
    end if
    go one back one element in List
end while

扫码关注云+社区

领取腾讯云代金券