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.
publicclassSolution{publicstaticvoidmain(String[]args){Scannerscanner=newScanner(System.in);doublepayment=scanner.nextDouble();scanner.close();// Create NumberFormat instances for each required localeNumberFormatusFormat=NumberFormat.getCurrencyInstance(Locale.US);NumberFormatindiaFormat=NumberFormat.getCurrencyInstance(newLocale("en","IN"));NumberFormatchinaFormat=NumberFormat.getCurrencyInstance(Locale.CHINA);NumberFormatfranceFormat=NumberFormat.getCurrencyInstance(Locale.FRANCE);// Format the payment value according to each localeStringus=usFormat.format(payment);Stringindia=indiaFormat.format(payment);Stringchina=chinaFormat.format(payment);Stringfrance=franceFormat.format(payment);// Print each formatted currency valueSystem.out.println("US: "+us);System.out.println("India: "+india);System.out.println("China: "+china);System.out.println("France: "+france);}}
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 →
This solution passes validation for Java 8