Hackerrank – Java Solution – Java Currency Formatter Solution

Problem Name – Java Currency Formatter
Problem Link –  Java Currency Formatter 
Level – Introduction Challenges

Java Code

import java.util.Scanner;
import java.text.NumberFormat;
import java.util.Locale;

public class Solution {
public static void main(String[] args) {
/* Save input */
Scanner scan = new Scanner(System.in);
double payment = scan.nextDouble();

/* Create custom Locale for India - I used the "IANA Language Subtag Registry" to find India's country code */
Locale indiaLocale = new Locale("en", "IN");

/* Create NumberFormats using Locales */
NumberFormat us = NumberFormat.getCurrencyInstance(Locale.US);
NumberFormat india = NumberFormat.getCurrencyInstance(indiaLocale);
NumberFormat china = NumberFormat.getCurrencyInstance(Locale.CHINA);
NumberFormat france = NumberFormat.getCurrencyInstance(Locale.FRANCE);

/* Print output */
System.out.println("US: " + us.format(payment));
System.out.println("India: " + india.format(payment));
System.out.println("China: " + china.format(payment));
System.out.println("France: " + france.format(payment));


Hackerrank - Java Solution - Java Currency Formatter Solution

Tags: HackerRank Online Judge Solution, HackerRank OJ Solution list, HackerRank Problems Solution, HackerRank solver, HackerRank all problem solution list, HackerRank solution in java, Hackerrank Java Solution, Hackerrank – Java Solution – Java Currency Formatter Solution

By Maniruzzaman Akash

Maniruzzaman Akash is a freelance web developer with most popular Laravel PHP frameork and Vue JS

Leave a Reply

Your email address will not be published. Required fields are marked *