Calender Program
Given a double-precision number, , denoting an amount of money, use the NumberFormat class' getCurrencyInstance method to convert 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.util.*;
import java.text.*;
public class Solution {
public static String formatPayment(double payment, Locale locale) {
return NumberFormat.getCurrencyInstance(locale).format(payment);
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
double payment = scanner.nextDouble();
scanner.close();
// Write your code here.
System.out.println("US: " + formatPayment(payment, Locale.US));
System.out.println("India: " + formatPayment(payment, new Locale("en", "In")));
System.out.println("China: " + formatPayment(payment, Locale.CHINA));
System.out.println("France: " + formatPayment(payment, Locale.FRANCE));
}
}
Comments
Post a Comment