Hackerrank - Java Solution - Java Currency Formatter Solution - Online Judge Solution

Latest

It is a free Online judges problems solution list. Here you can find UVA online Judge Solution, URI Online Judge Solution, Code Marshal Online Judge Solution, Spoz Online Judge Problems Solution

Tuesday, December 12, 2017

Hackerrank - Java Solution - Java Currency Formatter Solution

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();
        scan.close();

        /* 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));
    }
}

Output: 
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

3 comments:

  1. This article explores the essence of tournaments, delving into their cultural significance, the competitive spirit they evoke, and the sense of community they foster. Gacha99

    ReplyDelete