We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
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));
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Java Currency Formatter
You are viewing a single comment's thread. Return to all comments →
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 {
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));
}