Skip to content

Commit d732ded

Browse files
committed
Add 4 solutions of Introduction sub-domain of Java domain
- Java Int to String - Java Static Initializer Block - Java Date and Time - Java Currency Formatter
1 parent 2009e49 commit d732ded

4 files changed

Lines changed: 55 additions & 10 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import java.io.*;
2+
import java.util.*;
3+
import java.text.*;
4+
5+
public class JavaCurrencyFormatter {
6+
7+
public static void main(String[] args) {
8+
Scanner sc = new Scanner(System.in);
9+
double payment = sc.nextDouble();
10+
sc.close();
11+
12+
NumberFormat us = NumberFormat.getCurrencyInstance(Locale.US);
13+
NumberFormat india = NumberFormat.getCurrencyInstance(new Locale("en", "IN"));
14+
NumberFormat china = NumberFormat.getCurrencyInstance(Locale.CHINA);
15+
NumberFormat france = NumberFormat.getCurrencyInstance(Locale.FRANCE);
16+
17+
System.out.println("US: " + us.format(payment));
18+
System.out.println("India: " + india.format(payment));
19+
System.out.println("China: " + china.format(payment));
20+
System.out.println("France: " + france.format(payment));
21+
}
22+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import java.io.*;
2+
import java.util.*;
3+
import java.time.LocalDate;
4+
5+
public class JavaDateAndTime {
6+
7+
public static void main(String[] args) {
8+
Scanner in = new Scanner(System.in);
9+
int mm = in.nextInt();
10+
int dd = in.nextInt();
11+
int yy = in.nextInt();
12+
13+
LocalDate dt = LocalDate.of(yy, mm, dd);
14+
System.out.print(dt.getDayOfWeek());
15+
16+
in.close();
17+
}
18+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
String s = String.valueOf(n);
2+
// String s = n + "";
3+
// String s = Integer.toString(n);
Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
pu
1+
public class JavaStaticInitializerBlock {
22

3-
static Scanner sc = new Scanner(System.in);
4-
static int H = sc.nextInt();
5-
static int B = sc.nextInt();
6-
static boolean flag = (H>0 && B>0);
7-
static{
8-
if(!flag){
9-
System.out.print("java.lang.Exception: Breadth and height must be positive");
10-
}
11-
}
3+
static Scanner sc = new Scanner(System.in);
4+
static int H = sc.nextInt();
5+
static int B = sc.nextInt();
6+
static boolean flag = (H > 0 && B > 0);
7+
static {
8+
if (!flag) {
9+
System.out.print("java.lang.Exception: Breadth and height must be positive");
10+
}
11+
}
12+
13+
}

0 commit comments

Comments
 (0)