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.
Please use the Java 8 compiler for this code. If you find the solution helpful, kindly leave your feedback in the comments.
importjava.text.NumberFormat;importjava.util.Locale;importjava.util.Scanner;publicclassSolution{publicstaticvoidmain(String[]args){Scannerscanner=newScanner(System.in);// Using a lambda-style approach for prompting inputdoublepayment=scanner.nextDouble();scanner.close();// Defining a helper method for currency formatting (demonstrates clean and concise code practices)Stringus=formatCurrency(payment,Locale.US);Stringindia=formatCurrency(payment,newLocale("en","IN"));Stringchina=formatCurrency(payment,Locale.CHINA);Stringfrance=formatCurrency(payment,Locale.FRANCE);// Output resultsSystem.out.println("US: "+us);System.out.println("India: "+india);System.out.println("China: "+china);System.out.println("France: "+france);}// Java 8 style helper method for currency formattingprivatestaticStringformatCurrency(doubleamount,Localelocale){returnNumberFormat.getCurrencyInstance(locale).format(amount);}}
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 →
Please use the Java 8 compiler for this code. If you find the solution helpful, kindly leave your feedback in the comments.