-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathHackerRank_CurrencyFormatter.java
More file actions
31 lines (23 loc) · 1.14 KB
/
HackerRank_CurrencyFormatter.java
File metadata and controls
31 lines (23 loc) · 1.14 KB
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
27
28
29
30
31
import java.util.*;
import java.text.*;
public class HackerRank_CurrencyFormatter {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
double payment = scanner.nextDouble();
scanner.close();
// Write your code here.
// Creating a Locale for India as there isn't one defined by defualt.
Locale indianLocale = new Locale("en", "IN");
// Initializing the variables.
String us, india, china, france;
// Get the number format from the getCurrencyInstance() method and then format "payment" variable according to that format.
us = NumberFormat.getCurrencyInstance(Locale.US).format(payment);
india = NumberFormat.getCurrencyInstance(indianLocale).format(payment);
china = NumberFormat.getCurrencyInstance(Locale.CHINA).format(payment);
france = NumberFormat.getCurrencyInstance(Locale.FRANCE).format(payment);
System.out.println("US: " + us);
System.out.println("India: " + india);
System.out.println("China: " + china);
System.out.println("France: " + france);
}
}