Hackerrank - Java Solution - Java Currency Formatter Solution
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:
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
y creating india locale
ReplyDeletenot working
ReplyDeleteThis 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