-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHackerrankJava0012.java
More file actions
26 lines (20 loc) · 890 Bytes
/
HackerrankJava0012.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
import java.text.NumberFormat;
import java.util.Locale;
import java.util.Scanner;
public class HackerrankJava0012 {
public static void main(String[] args) {
// Java Currency Formatter
// https://www.hackerrank.com/challenges/java-currency-formatter/problem?isFullScreen=true
Scanner scanner = new Scanner(System.in);
double payment = scanner.nextDouble();
scanner.close();
System.out.println("US: " + getFormettedResult(payment, Locale.US));
System.out.println("India: " + getFormettedResult(payment, new Locale("en", "IN")));
System.out.println("China: " + getFormettedResult(payment, Locale.CHINA));
System.out.println("France: " + getFormettedResult(payment, Locale.FRANCE));
}
private static String getFormettedResult(double payment, Locale locale) {
NumberFormat usFormat = NumberFormat.getCurrencyInstance(locale);
return usFormat.format(payment);
}
}