The problem context involves taking a number as input and formatting it into different currency formats. The program should be able to format the number into US, Indian, Chinese, and French currency formats.
CodeRankGPT is a tool powered by GPT-4 that quietly assists you during your coding interview, providing the solutions you need.
In real-time and absolutely undetectable 🥷
The solution approach involves using Java's NumberFormat class and Locale class. The NumberFormat class provides the getCurrencyInstance method which returns a currency format for the specified locale. The Locale class is used to specify the desired locale for which the currency format is needed. The program takes a number as input, formats it into the different currency formats, and then prints the formatted numbers.
/**
*
*/
package com.javaaid.hackerrank.solutions.languages.java.introduction;
import java.text.NumberFormat;
import java.util.Locale;
import java.util.Scanner;
/**
*
*/
public class JavaCurrencyFormatter {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
double payment = scanner.nextDouble();
scanner.close();
String us = NumberFormat.getCurrencyInstance(Locale.US).format(payment);
String india = NumberFormat.getCurrencyInstance(new Locale("en", "in")).format(payment);
String china = NumberFormat.getCurrencyInstance(Locale.CHINA).format(payment);
String 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);
}
}
If you have a HackerRank coding test coming up, you can use CodeRankGPT to your advantage. It will assist you during your interview and help ensure you get the job.
AI is here now, and other candidates might be using it to get ahead and win the job. 🧐
The form has been successfully submitted.