Skip to content

Added CurrencyFormatter.java #469

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions Hackerrank/java/2DArray.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import java.io.*;
import java.util.*;
import java.lang.*;

public class Solution {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
int[][] arr = new int[6][6];
for (int i = 0; i < 6; i++) {
for (int j = 0; j < 6; j++) {
arr[i][j] = sc.nextInt();
}
}
int max = Integer.MIN_VALUE;
int sum = 0;
for (int i = 1; i < 5; i++) {
for (int j = 1; j < 5; j++) {
sum = arr[i][j] + arr[i-1][j-1] + arr[i-1][j] + arr[i-1][j+1] + arr[i+1][j-1] + arr[i+1][j] + arr[i+1][j+1];
if(sum > max){
max = sum;
}
}
}
System.out.println(max);
}
}
29 changes: 29 additions & 0 deletions Hackerrank/java/CurrencyFormatter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import java.util.Scanner;
import java.text.NumberFormat;
import java.util.Locale;

public class Solution {

public static void main(String[] args) {
/* Read input */
Scanner scanner = new Scanner(System.in);
double payment = scanner.nextDouble();
scanner.close();

/* Create custom Locale for India.
I used the "IANA Language Subtag Registry" to find India's country code */
Locale indiaLocale = new Locale("en", "IN");

/* Create NumberFormats using Locales */
NumberFormat us = NumberFormat.getCurrencyInstance(Locale.US);
NumberFormat india = NumberFormat.getCurrencyInstance(indiaLocale);
NumberFormat china = NumberFormat.getCurrencyInstance(Locale.CHINA);
NumberFormat france = NumberFormat.getCurrencyInstance(Locale.FRANCE);

/* Print output */
System.out.println("US: " + us.format(payment));
System.out.println("India: " + india.format(payment));
System.out.println("China: " + china.format(payment));
System.out.println("France: " + france.format(payment));
}
}