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.
importjava.util.Scanner;importjava.util.Locale;importjava.text.NumberFormat;publicclassSolution{publicstaticvoidmain(String[]args){// Scanner - For the "payment" inputScannerscanner=newScanner(System.in);doublepayment=scanner.nextDouble();scanner.close();// Four NumberFormat instances - One for each localeNumberFormatf_US=NumberFormat.getCurrencyInstance(Locale.US);NumberFormatf_IN=NumberFormat.getCurrencyInstance(newLocale("en","IN"));NumberFormatf_CH=NumberFormat.getCurrencyInstance(Locale.CHINA);NumberFormatf_FR=NumberFormat.getCurrencyInstance(Locale.FRANCE);// Four System outputs - One for each localeSystem.out.println("US: "+f_US.format(payment));System.out.println("India: "+f_IN.format(payment));System.out.println("China: "+f_CH.format(payment));System.out.println("France: "+f_FR.format(payment));}}
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 →
Java 8 - Not optimal, but hopefully clear: