Java Currency Formatter | HACKERRANK

Asked: Anonymously |Category: JAVA

import java.io.*;

import java.util.*;

import java.text.*;

import java.math.*;

import java.util.regex.*;


public class Solution {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

double payment = scanner.nextDouble();

scanner.close();

NumberFormat usf=NumberFormat.getCurrencyInstance(Locale.US);

NumberFormat csf=NumberFormat.getCurrencyInstance(Locale.CHINA);

NumberFormat fsf=NumberFormat.getCurrencyInstance(Locale.FRANCE);

NumberFormat isf=NumberFormat.getCurrencyInstance(new Locale("en","in"));

String us=usf.format(payment);

String india=isf.format(payment);

String china=csf.format(payment);

String france=fsf.format(payment);

System.out.println("US: " + us);

System.out.println("India: " + india);

System.out.println("China: " + china);

System.out.println("France: " + france);

}

}


2 views

Recent Posts

See All

"Believe you can and you're halfway there"