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.
public class Solution {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
double payment = scanner.nextDouble();
scanner.close();
// Create India locale manually
Locale indiaLocale = new Locale("en", "IN");
// Create currency formatters
NumberFormat usFormat = NumberFormat.getCurrencyInstance(Locale.US);
NumberFormat indiaFormat = NumberFormat.getCurrencyInstance(indiaLocale);
NumberFormat chinaFormat = NumberFormat.getCurrencyInstance(Locale.CHINA);
NumberFormat franceFormat = NumberFormat.getCurrencyInstance(Locale.FRANCE);
// Format the values
String us = usFormat.format(payment);
String india = indiaFormat.format(payment);
String china = chinaFormat.format(payment);
String france = franceFormat.format(payment);
// Output exactly as required (no extra spaces)
System.out.println("US: " + us);
System.out.println("India: " + india);
System.out.println("China: " + china);
System.out.println("France: " + france);
}
}
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 →
import java.util.; import java.text.;
public class Solution { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); double payment = scanner.nextDouble(); scanner.close();
}