-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCurrencyFormatter.java
34 lines (29 loc) · 1.39 KB
/
CurrencyFormatter.java
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
32
33
34
package HackerRank.Introduction;
// Given a double-precision number, 'payment', denoting an amount of money, use the NumberFormat class'
// getCurrencyInstance method to convert 'payment' into the US, Indian, Chinese, and French currency formats.
// Then print the formatted values as follows:
//
// US: formattedPayment
// India: formattedPayment
// China: formattedPayment
// France: formattedPayment
import java.text.NumberFormat;
import java.util.Locale;
import java.util.Scanner;
public class CurrencyFormatter {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
double payment = scanner.nextDouble();
scanner.close();
// Creating a formatted output
String us = String.valueOf(NumberFormat.getCurrencyInstance(Locale.US).format(payment));
String india = String.valueOf(NumberFormat.getCurrencyInstance(new Locale("en", "in")).format(payment));
String china = String.valueOf(NumberFormat.getCurrencyInstance(Locale.CHINA).format(payment));
String france = String.valueOf(NumberFormat.getCurrencyInstance(Locale.FRANCE).format(payment));
// Printing the formatted strings in correspondence to the needed currency
System.out.println("US: " + us);
System.out.println("India: " + india);
System.out.println("China: " + china);
System.out.println("France: " + france);
}
}