- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHackerrankJava0012.java
More file actions
Latest commit
26 lines (20 loc) · 890 Bytes
/
Copy pathHackerrankJava0012.java
File metadata and controls
26 lines (20 loc) · 890 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
importjava.text.NumberFormat;
importjava.util.Locale;
importjava.util.Scanner;
publicclassHackerrankJava0012 {
publicstaticvoidmain(String[] args) {
// Java Currency Formatter
// https://www.hackerrank.com/challenges/java-currency-formatter/problem?isFullScreen=true
Scannerscanner = newScanner(System.in);
doublepayment = scanner.nextDouble();
scanner.close();
System.out.println("US: " + getFormettedResult(payment, Locale.US));
System.out.println("India: " + getFormettedResult(payment, newLocale("en", "IN")));
System.out.println("China: " + getFormettedResult(payment, Locale.CHINA));
System.out.println("France: " + getFormettedResult(payment, Locale.FRANCE));
}
privatestaticStringgetFormettedResult(doublepayment, Localelocale) {
NumberFormatusFormat = NumberFormat.getCurrencyInstance(locale);
returnusFormat.format(payment);
}
}