Java Currency Formatter

  • + 1 comment

    My code, when run, prints the Chinese yuan with two stikes on Y, while the expected output demands the yuan character with only one strike on Y. Hence, my code is not passing the test case.

    Any suggestions are cited and welcome.

    public class Solution {

    public static void main(String[] args) {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
    
        Scanner scanner = new Scanner(System.in);
    

    double payment = scanner.nextDouble(); var u = NumberFormat.getCurrencyInstance(Locale.US); var i = NumberFormat.getCurrencyInstance(new Locale("en", "IN")); var c = NumberFormat.getCurrencyInstance(new Locale("zh","CN")); var f = NumberFormat.getCurrencyInstance(Locale.FRANCE); System.out.println("US: "+u.format(payment)); System.out.println("India: "+i.format(payment).replace(i.getCurrency().getSymbol(), "Rs.")); System.out.println("China: "+c.format(payment)); System.out.println("France: "+f.format(payment));

    }
    

    }