sitelink1 | |
---|---|
sitelink2 | |
sitelink3 | |
sitelink4 | |
sitelink5 | |
sitelink6 |
http://www.okjsp.pe.kr/seq/25434/*
제목 : 숫자 에 대응 되는 패턴의 형식화 #1
ChoiceFormat 은 숫자 범위에 관한 형식화를 한다. 사용자가 지정한 숫자 범위 내의 문자를 직접 지정하는 것이다. 이를 가장 일반 적으로 적용 할 수 있는 것은 [요일표시, 월표시, 시간표시 또는 0~9까지의 수의 이름] 등이다. 즉, 0은 일요일, 1은 월요일 등으로 표현 하는 경우이다.
ChoiceFormat의 생성자는 두개가 있다.
1. 수의 경계를 double형 배열과 스트링형 배열을 인자로 받는 것.
2. 직접 패턴을 정의 해서 인자로 넘겨 주는 것.
다음 예제를 살펴 보자 . 예제에는 숫자를 형식화 하여 요일 및 숫자를 표현 하는 것으로 테스트를 하겠다.
숫자가 패턴으로 형식화 될 때는 0.0~0.9까지는 0번째로, 1.0~1.9까지는 1번째... 등로로 수행 한다.
I. 첫 번 째 생성자를 이용한 예제.
*/
import java.text.ChoiceFormat;
import java.lang.Math;
public class ChoiceFormatTesting{
public static void main(String[] args) {
double[] aNumberBoundary = { 0, 1, 2, 3, 4, 5, 6 };
String[] formats = { "일", "월", "화", "수", "목", "금", "토" };
//형식화 숫자 범위와 형식화 테이터를 배열로 생성하여 사용 할 경우
ChoiceFormat cf = new ChoiceFormat( aNumberBoundary, formats );
System.out.println( "Pattern : " + cf.toPattern() );
for( int i = 0; i < formats.length; i++ ){
print( cf, (double)i );
}
System.out.println( "-----------------------------------" );
//다음은 형식화를 위한 숫자를 직접 지정해서 살펴 본 것이다.
print( cf, 0.5 );
print( cf, 1.7 );
print( cf, 2.0 );
print( cf, 3.5 );
print( cf, 4.9 );
print( cf, 5.3 );
print( cf, 6.2 );
}
private static void print( ChoiceFormat cfArgs, double boundary ){
System.out.print( "Boundary Limit value is "
+ (cfArgs.getLimits())[(int)boundary] + "t" );
System.out.println( "Expression : " + cfArgs.format( boundary ) );
}
}
/*
II. 직접 패턴을 지정 해서 이용 한 예제.
*/
import java.text.ChoiceFormat;
import java.lang.Math;
public class ChoiceFormatTesting{
public static void main(String[] args) {
//형식화 패턴을 지정해서 수행 한 경우
ChoiceFormat cf =
new ChoiceFormat(
"0.0#하나|1.0#둘|2.0#셋|3.0#넷|4.0#다섯|5.0#여섯"
+"|6.0#일곱|7.0#여덟|8.0#아홉|9.0#아홉|10.0#열" );
System.out.println( "Pattern : " + cf.toPattern() );
for( int i = 0; i < 11; i++ ){
print( cf, (double)i );
}
System.out.println( "----------------------------------" );
//다음은 형식화를 위한 숫자를 직접 지정해서 살펴 본 것이다.
print( cf, 0.5 );
print( cf, 1.7 );
print( cf, 2.0 );
print( cf, 3.5 );
print( cf, 4.9 );
print( cf, 5.3 );
print( cf, 6.2 );
print( cf, 7.1 );
print( cf, 8.9 );
print( cf, 9.94);
print( cf, 10.0 );
}
private static void print( ChoiceFormat cfArgs, double boundary ){
System.out.print( "Boundary Limit value is "
+ (cfArgs.getLimits())[(int)boundary] + "t" );
System.out.println( "Expression : " + cfArgs.format( boundary ) );
}
}
/*
위 예제를 수행 해 보면 ChoiceFormat이 무엇을 위한 것인지 잘 알 수 있을 것이다.
또 ChoiceFormat은 형식화를 위해 "|"로 형식화를 구분하며 "#"으로 패턴과 짝을 이룬다는 것을 볼 수 있을 것이다.
==================================
너부리 - 최인국(희선)
이 문서는 자유롭게 배포 할 수 있으나 서
명은 삭제 할 수 없습니다^^
==================================
http://www.javaxcafe.com
neoburi at javaxcafe.com
msn:decode40 at hotmail.com
ICQ : 100033382
==================================
*/
제목 : 숫자 에 대응 되는 패턴의 형식화 #1
ChoiceFormat 은 숫자 범위에 관한 형식화를 한다. 사용자가 지정한 숫자 범위 내의 문자를 직접 지정하는 것이다. 이를 가장 일반 적으로 적용 할 수 있는 것은 [요일표시, 월표시, 시간표시 또는 0~9까지의 수의 이름] 등이다. 즉, 0은 일요일, 1은 월요일 등으로 표현 하는 경우이다.
ChoiceFormat의 생성자는 두개가 있다.
1. 수의 경계를 double형 배열과 스트링형 배열을 인자로 받는 것.
2. 직접 패턴을 정의 해서 인자로 넘겨 주는 것.
다음 예제를 살펴 보자 . 예제에는 숫자를 형식화 하여 요일 및 숫자를 표현 하는 것으로 테스트를 하겠다.
숫자가 패턴으로 형식화 될 때는 0.0~0.9까지는 0번째로, 1.0~1.9까지는 1번째... 등로로 수행 한다.
I. 첫 번 째 생성자를 이용한 예제.
*/
import java.text.ChoiceFormat;
import java.lang.Math;
public class ChoiceFormatTesting{
public static void main(String[] args) {
double[] aNumberBoundary = { 0, 1, 2, 3, 4, 5, 6 };
String[] formats = { "일", "월", "화", "수", "목", "금", "토" };
//형식화 숫자 범위와 형식화 테이터를 배열로 생성하여 사용 할 경우
ChoiceFormat cf = new ChoiceFormat( aNumberBoundary, formats );
System.out.println( "Pattern : " + cf.toPattern() );
for( int i = 0; i < formats.length; i++ ){
print( cf, (double)i );
}
System.out.println( "-----------------------------------" );
//다음은 형식화를 위한 숫자를 직접 지정해서 살펴 본 것이다.
print( cf, 0.5 );
print( cf, 1.7 );
print( cf, 2.0 );
print( cf, 3.5 );
print( cf, 4.9 );
print( cf, 5.3 );
print( cf, 6.2 );
}
private static void print( ChoiceFormat cfArgs, double boundary ){
System.out.print( "Boundary Limit value is "
+ (cfArgs.getLimits())[(int)boundary] + "t" );
System.out.println( "Expression : " + cfArgs.format( boundary ) );
}
}
/*
II. 직접 패턴을 지정 해서 이용 한 예제.
*/
import java.text.ChoiceFormat;
import java.lang.Math;
public class ChoiceFormatTesting{
public static void main(String[] args) {
//형식화 패턴을 지정해서 수행 한 경우
ChoiceFormat cf =
new ChoiceFormat(
"0.0#하나|1.0#둘|2.0#셋|3.0#넷|4.0#다섯|5.0#여섯"
+"|6.0#일곱|7.0#여덟|8.0#아홉|9.0#아홉|10.0#열" );
System.out.println( "Pattern : " + cf.toPattern() );
for( int i = 0; i < 11; i++ ){
print( cf, (double)i );
}
System.out.println( "----------------------------------" );
//다음은 형식화를 위한 숫자를 직접 지정해서 살펴 본 것이다.
print( cf, 0.5 );
print( cf, 1.7 );
print( cf, 2.0 );
print( cf, 3.5 );
print( cf, 4.9 );
print( cf, 5.3 );
print( cf, 6.2 );
print( cf, 7.1 );
print( cf, 8.9 );
print( cf, 9.94);
print( cf, 10.0 );
}
private static void print( ChoiceFormat cfArgs, double boundary ){
System.out.print( "Boundary Limit value is "
+ (cfArgs.getLimits())[(int)boundary] + "t" );
System.out.println( "Expression : " + cfArgs.format( boundary ) );
}
}
/*
위 예제를 수행 해 보면 ChoiceFormat이 무엇을 위한 것인지 잘 알 수 있을 것이다.
또 ChoiceFormat은 형식화를 위해 "|"로 형식화를 구분하며 "#"으로 패턴과 짝을 이룬다는 것을 볼 수 있을 것이다.
==================================
너부리 - 최인국(희선)
이 문서는 자유롭게 배포 할 수 있으나 서
명은 삭제 할 수 없습니다^^
==================================
http://www.javaxcafe.com
neoburi at javaxcafe.com
msn:decode40 at hotmail.com
ICQ : 100033382
==================================
*/