수업
+26 형식화 클래스: Decimal Format, SimpleDateFormat, ChoiceFormat
hs_developer
2022. 6. 9. 16:16
Decimal Format
12,345,678
public static void main(String[] args) {
DecimalFormat df = new DecimalFormat();
int data = 12345678;
System.out.println(df.format(data));
}
SimpleDateFormat
2022-06-09 04:04:14
public static void main(String[] args) {
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
System.out.println(sdf.format(date));
}
ChoiceFormat
100 : A
90 : A
85 : B
99 : A
45 : F
67 : D
78 : C
public static void main(String[] args) {
double[] limit = {59, 60, 70, 80, 90};
String[] grade = {"F", "D", "C", "B", "A"};
int[] score = {100, 90, 85, 99, 45, 67, 78};
ChoiceFormat form = new ChoiceFormat(limit, grade);
for(int i=0; i<score.length; i++)
{
System.out.println(score[i]+" : " + form.format(score[i]));
}
}